From: Jim Meyering Date: Sat, 14 Feb 2015 01:20:06 +0000 (-0800) Subject: ExceptionWrapperTest.cpp vs clang's new warning about side effects in typeid argument... X-Git-Tag: v0.27.0~37 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=82b788f506cb45e44921c42337efb93e4bfe3656;p=folly.git ExceptionWrapperTest.cpp vs clang's new warning about side effects in typeid argument list 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 --- diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index 96b09334..ce051198 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -176,7 +176,14 @@ TEST(ExceptionWrapper, with_exception_test) { EXPECT_EQ(ew2.class_name(), "IntException"); ew2.with_exception([&](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