A few fixes for clang support
authorMarcelo Juchem <marcelo@fb.com>
Fri, 25 Jan 2013 04:49:47 +0000 (20:49 -0800)
committerJordan DeLong <jdelong@fb.com>
Mon, 4 Feb 2013 17:25:55 +0000 (09:25 -0800)
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

folly/Format-inl.h
folly/Format.h
folly/Optional.h
folly/Traits.h
folly/test/HasMemberFnTraitsTest.cpp

index bba7be85ed588e310412f70054f7e1c407c3dfb0..831d3c82149a5420f9c073ff3bc0583bfc3d62e2 100644 (file)
@@ -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 {
index 9571a9a41fdfb917a9aec44814c0b84ab31c2267..628a2a29fd0ffbcea69895ebb5e6ad6439ae7298 100644 (file)
@@ -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"
index 506bbb8972a88657a12b02a0634ea09dfe7f1540..5b574f5b509dd557189a9aa3eb5f2836b9d4d37a 100644 (file)
@@ -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>,
index d2fad50ee842d3be52c9881bc5bbd32da96db52c..d3002dce5a07bd90a3171fb0136c132843c4d1f3 100644 (file)
@@ -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);
index 50efce83ca97b425f969a9707077cc1e96293c40..470eb5997afe8856e04ed074babb11ce7961550e 100644 (file)
@@ -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)));