summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan T. Lavavej <stl@exchange.microsoft.com>2016-12-06 01:14:43 +0000
committerStephan T. Lavavej <stl@exchange.microsoft.com>2016-12-06 01:14:43 +0000
commitf41847c401789d8f4a6fce0827579c7e3cfc47d6 (patch)
treeb2d14321309b409cb09e5806ec813ca195cb4689
parentbaa547b99670a3652b8a1b0b47e853d58ee18093 (diff)
downloadbcm5719-llvm-f41847c401789d8f4a6fce0827579c7e3cfc47d6.tar.gz
bcm5719-llvm-f41847c401789d8f4a6fce0827579c7e3cfc47d6.zip
[libcxx] [test] D27268: Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.
Use static_cast<int> when storing size_t in int (or passing size_t to int). Also, remove a spurious semicolon in test/support/archetypes.hpp. test/support/count_new.hpp Additionally, change data members (and parameters) to size_t. llvm-svn: 288752
-rw-r--r--libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp4
-rw-r--r--libcxx/test/support/archetypes.hpp12
-rw-r--r--libcxx/test/support/count_new.hpp18
3 files changed, 17 insertions, 17 deletions
diff --git a/libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp b/libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
index f17f5820d20..e6ed0129ddc 100644
--- a/libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp
@@ -23,9 +23,9 @@
struct TestT {
int x;
int size;
- constexpr TestT(std::initializer_list<int> il) : x(*il.begin()), size(il.size()) {}
+ constexpr TestT(std::initializer_list<int> il) : x(*il.begin()), size(static_cast<int>(il.size())) {}
constexpr TestT(std::initializer_list<int> il, const int*)
- : x(*il.begin()), size(il.size()) {}
+ : x(*il.begin()), size(static_cast<int>(il.size())) {}
};
int main()
diff --git a/libcxx/test/support/archetypes.hpp b/libcxx/test/support/archetypes.hpp
index da6212301ea..f442b592a26 100644
--- a/libcxx/test/support/archetypes.hpp
+++ b/libcxx/test/support/archetypes.hpp
@@ -69,11 +69,11 @@ struct TestBase {
}
template <bool Dummy = true, typename std::enable_if<Dummy && Explicit, bool>::type = true>
explicit TestBase(std::initializer_list<int>& il, int = 0) noexcept
- : value(il.size()) {
+ : value(static_cast<int>(il.size())) {
++alive; ++constructed; ++value_constructed;
}
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
- explicit TestBase(std::initializer_list<int>& il, int = 0) noexcept : value(il.size()) {
+ explicit TestBase(std::initializer_list<int>& il, int = 0) noexcept : value(static_cast<int>(il.size())) {
++alive; ++constructed; ++value_constructed;
}
TestBase& operator=(int xvalue) noexcept {
@@ -135,9 +135,9 @@ struct ValueBase {
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
constexpr ValueBase(int, int y) : value(y) {}
template <bool Dummy = true, typename std::enable_if<Dummy && Explicit, bool>::type = true>
- explicit constexpr ValueBase(std::initializer_list<int>& il, int = 0) : value(il.size()) {}
+ explicit constexpr ValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
- constexpr ValueBase(std::initializer_list<int>& il, int = 0) : value(il.size()) {}
+ constexpr ValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
TEST_CONSTEXPR_CXX14 ValueBase& operator=(int xvalue) noexcept {
value = xvalue;
return *this;
@@ -193,9 +193,9 @@ struct TrivialValueBase {
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
constexpr TrivialValueBase(int, int y) : value(y) {}
template <bool Dummy = true, typename std::enable_if<Dummy && Explicit, bool>::type = true>
- explicit constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(il.size()) {}
+ explicit constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
- constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(il.size()) {};
+ constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
int value;
protected:
constexpr TrivialValueBase() noexcept : value(0) {}
diff --git a/libcxx/test/support/count_new.hpp b/libcxx/test/support/count_new.hpp
index 923e4951348..7589784d02d 100644
--- a/libcxx/test/support/count_new.hpp
+++ b/libcxx/test/support/count_new.hpp
@@ -59,12 +59,12 @@ public:
int outstanding_new;
int new_called;
int delete_called;
- int last_new_size;
+ std::size_t last_new_size;
int outstanding_array_new;
int new_array_called;
int delete_array_called;
- int last_new_array_size;
+ std::size_t last_new_array_size;
public:
void newCalled(std::size_t s)
@@ -174,12 +174,12 @@ public:
return disable_checking || n != delete_called;
}
- bool checkLastNewSizeEq(int n) const
+ bool checkLastNewSizeEq(std::size_t n) const
{
return disable_checking || n == last_new_size;
}
- bool checkLastNewSizeNotEq(int n) const
+ bool checkLastNewSizeNotEq(std::size_t n) const
{
return disable_checking || n != last_new_size;
}
@@ -214,12 +214,12 @@ public:
return disable_checking || n != delete_array_called;
}
- bool checkLastNewArraySizeEq(int n) const
+ bool checkLastNewArraySizeEq(std::size_t n) const
{
return disable_checking || n == last_new_array_size;
}
- bool checkLastNewArraySizeNotEq(int n) const
+ bool checkLastNewArraySizeNotEq(std::size_t n) const
{
return disable_checking || n != last_new_array_size;
}
@@ -304,10 +304,10 @@ struct RequireAllocationGuard {
void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; }
~RequireAllocationGuard() {
- assert(globalMemCounter.checkOutstandingNewEq(m_outstanding_new_on_init));
+ assert(globalMemCounter.checkOutstandingNewEq(static_cast<int>(m_outstanding_new_on_init)));
std::size_t Expect = m_new_count_on_init + m_req_alloc;
- assert(globalMemCounter.checkNewCalledEq(Expect) ||
- (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(Expect)));
+ assert(globalMemCounter.checkNewCalledEq(static_cast<int>(Expect)) ||
+ (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast<int>(Expect))));
}
private:
OpenPOWER on IntegriCloud