Summary: fixes for clang support
Test Plan:
rm -rf ~/fbcode/_build/* && fbconfig --clang folly/test && fbmake
rm -rf ~/fbcode/_build/* && fbconfig folly/test && fbmake
_bin/folly/test/format_test
_bin/folly/test/optional_test
_bin/folly/test/has_member_fn_traits_test
Reviewed By: tudorb@fb.com
FB internal diff:
D688295
UT uval;
char sign;
if (std::is_signed<T>::value) {
- if (val_ < 0) {
+ if (folly::is_negative(val_)) {
uval = static_cast<UT>(-val_);
sign = '-';
} else {
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "folly/FBVector.h"
#include "folly/Conv.h"
#include "folly/Range.h"
+#include "folly/Traits.h"
#include "folly/Likely.h"
#include "folly/String.h"
#include "folly/small_vector.h"
/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* gcc-4.7 warns about use of uninitialized memory around the use of storage_
* even though this is explicitly initialized at each point.
*/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wuninitialized"
-#pragma GCC diagnostic ignored "-Wpragmas"
-#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wuninitialized"
+# pragma GCC diagnostic ignored "-Wpragmas"
+# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif // __GNUC__
template<class Value>
class Optional : boost::totally_ordered<Optional<Value>,
enum { value = std::is_same<T, T1>::value || IsOneOf<T, Ts...>::value };
};
+/*
+ * Complementary type traits to check for a negative value.
+ *
+ * if(x < 0) yields an error in clang for unsigned types when -Werror is used
+ */
+
+namespace detail {
+
+template <typename T, bool>
+struct is_negative_impl {
+ constexpr static bool check(T x) { return x < 0; }
+};
+
+template <typename T>
+struct is_negative_impl<T, false> {
+ constexpr static bool check(T x) { return false; }
+};
+
+} // namespace detail {
+
+template <typename T>
+constexpr bool is_negative(T x) {
+ return folly::detail::is_negative_impl<T, std::is_signed<T>::value>::check(x);
+}
+
} // namespace folly
FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string);
void test() const volatile;
};
-#define LOG_VALUE(x) []() { \
- LOG(INFO) << #x << ": " << boolalpha << (x); \
- return x; \
-}()
+bool log_value(const char* what, bool result) {
+ LOG(INFO) << what << ": " << boolalpha << result;
+ return result;
+}
+
+#define LOG_VALUE(x) log_value(#x, x)
TEST(HasMemberFnTraits, DirectMembers) {
EXPECT_TRUE(LOG_VALUE((has_test<Foo, int()>::value)));