Permalink
Browse files

A few fixes for clang support

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
  • Loading branch information...
1 parent 4988b28 commit 378a3bbc7ec5298f92f8c43083c2b0f7836348a6 @juchem juchem committed with jdelong Jan 25, 2013
Showing with 41 additions and 11 deletions.
  1. +1 −1 folly/Format-inl.h
  2. +2 −1 folly/Format.h
  3. +7 −5 folly/Optional.h
  4. +25 −0 folly/Traits.h
  5. +6 −4 folly/test/HasMemberFnTraitsTest.cpp
View
@@ -377,7 +377,7 @@ class FormatValue<
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 {
View
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -30,6 +30,7 @@
#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"
View
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -73,10 +73,12 @@ const None none = nullptr;
* 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>,
View
@@ -277,6 +277,31 @@ struct IsOneOf<T, T1, Ts...> {
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);
@@ -65,10 +65,12 @@ struct CV {
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)));

0 comments on commit 378a3bb

Please sign in to comment.