ExceptionWrapperTest.cpp vs clang's new warning about side effects in typeid argument...
authorJim Meyering <meyering@fb.com>
Sat, 14 Feb 2015 01:20:06 +0000 (17:20 -0800)
committerAlecs King <int@fb.com>
Tue, 3 Mar 2015 03:21:07 +0000 (19:21 -0800)
Summary:
Disable the -Wunevaluated-expression warning for this test:

EXPECT_EQ(typeid(ie), typeid(IntException));

Otherwise, clang warns about the unevaluated expression because
the expansion of EXPECT_EQ applies sizeof to an expression
with side effects:

folly/test/ExceptionWrapperTest.cpp:179:122: error: expression with side effects has no effect in an unevaluated context [-Werror,-Wunevaluated-expression]
switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing::internal::IsNullLiteralHelper(typeid(ie))) == 1)>::Compare("typeid(ie)", "typeid(IntException)", typeid(ie), typeid(IntException)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "folly/test/ExceptionWrapperTest.cpp", 179, gtest_ar.failure_message()) = ::testing::Message();

Test Plan:
Ensure this compiles with clang-3.4, 3.5 and clang:dev.
I.e., ensure that this prints PASS at the end.

for i in '' 3.5 dev; do
test -n "$i" && i=--with-project-version=clang:$i
fbconfig -r --clang $i folly/test:exception_wrapper_test && fbmake dbgo
done && echo PASS

Reviewed By: mpawlowski@fb.com

Subscribers: mathieubaudet, folly-diffs@, yfeldblum

FB internal diff: D1850778

Tasks: 6244745

Signature: t1:1850778:1424111029:136478e9a3cc3a219047547d501de4c579a1a181

folly/test/ExceptionWrapperTest.cpp

index 96b09334fbcbe0a26cfadb4b846b0ed2b08e778f..ce051198dff176124d7e78ae92d40657fd4a9670 100644 (file)
@@ -176,7 +176,14 @@ TEST(ExceptionWrapper, with_exception_test) {
   EXPECT_EQ(ew2.class_name(), "IntException");
   ew2.with_exception<AbstractIntException>([&](AbstractIntException& ie) {
       EXPECT_EQ(ie.getInt(), expected);
+#if defined __clang__ && (__clang_major__ > 3 || __clang_minor__ >= 6)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wunevaluated-expression"
+#endif
       EXPECT_EQ(typeid(ie), typeid(IntException));
+#if defined __clang__ && (__clang_major__ > 3 || __clang_minor__ >= 6)
+# pragma clang diagnostic pop
+#endif
     });
 
   // Test with const this.  If this compiles and does not crash due to