From 378a3bbc7ec5298f92f8c43083c2b0f7836348a6 Mon Sep 17 00:00:00 2001 From: Marcelo Juchem Date: Thu, 24 Jan 2013 20:49:47 -0800 Subject: [PATCH] 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 --- folly/Format-inl.h | 2 +- folly/Format.h | 3 ++- folly/Optional.h | 12 +++++++----- folly/Traits.h | 25 +++++++++++++++++++++++++ folly/test/HasMemberFnTraitsTest.cpp | 10 ++++++---- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/folly/Format-inl.h b/folly/Format-inl.h index bba7be85..831d3c82 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -377,7 +377,7 @@ class FormatValue< UT uval; char sign; if (std::is_signed::value) { - if (val_ < 0) { + if (folly::is_negative(val_)) { uval = static_cast(-val_); sign = '-'; } else { diff --git a/folly/Format.h b/folly/Format.h index 9571a9a4..628a2a29 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -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" diff --git a/folly/Optional.h b/folly/Optional.h index 506bbb89..5b574f5b 100644 --- a/folly/Optional.h +++ b/folly/Optional.h @@ -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 Optional : boost::totally_ordered, diff --git a/folly/Traits.h b/folly/Traits.h index d2fad50e..d3002dce 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -277,6 +277,31 @@ struct IsOneOf { enum { value = std::is_same::value || IsOneOf::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 +struct is_negative_impl { + constexpr static bool check(T x) { return x < 0; } +}; + +template +struct is_negative_impl { + constexpr static bool check(T x) { return false; } +}; + +} // namespace detail { + +template +constexpr bool is_negative(T x) { + return folly::detail::is_negative_impl::value>::check(x); +} + } // namespace folly FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string); diff --git a/folly/test/HasMemberFnTraitsTest.cpp b/folly/test/HasMemberFnTraitsTest.cpp index 50efce83..470eb599 100644 --- a/folly/test/HasMemberFnTraitsTest.cpp +++ b/folly/test/HasMemberFnTraitsTest.cpp @@ -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::value))); -- 2.34.1