r204308 - [-Wunreachable-code] constexpr functions can be used as configuration values.
Ted Kremenek
kremenek at apple.com
Wed Mar 19 23:07:36 PDT 2014
Author: kremenek
Date: Thu Mar 20 01:07:35 2014
New Revision: 204308
URL: http://llvm.org/viewvc/llvm-project?rev=204308&view=rev
Log:
[-Wunreachable-code] constexpr functions can be used as configuration values.
Modified:
cfe/trunk/lib/Analysis/ReachableCode.cpp
cfe/trunk/test/SemaCXX/warn-unreachable.cpp
Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=204308&r1=204307&r2=204308&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Thu Mar 20 01:07:35 2014
@@ -139,6 +139,11 @@ static bool isConfigurationValue(const S
S = Ex->IgnoreParenCasts();
switch (S->getStmtClass()) {
+ case Stmt::CallExprClass: {
+ const FunctionDecl *Callee =
+ dyn_cast_or_null<FunctionDecl>(cast<CallExpr>(S)->getCalleeDecl());
+ return Callee ? Callee->isConstexpr() : false;
+ }
case Stmt::DeclRefExprClass: {
const DeclRefExpr *DR = cast<DeclRefExpr>(S);
const ValueDecl *D = DR->getDecl();
Modified: cfe/trunk/test/SemaCXX/warn-unreachable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unreachable.cpp?rev=204308&r1=204307&r2=204308&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unreachable.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unreachable.cpp Thu Mar 20 01:07:35 2014
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -verify -fblocks -Wunreachable-code-aggressive -Wno-unused-value
+// RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -verify -fblocks -std=c++11 -Wunreachable-code-aggressive -Wno-unused-value
int &halt() __attribute__((noreturn));
int &live();
@@ -234,3 +234,24 @@ Frobozz test_return_object_control_flow(
return Frobozz(flag ? 42 : 24); // expected-warning {{code will never be executed}}
}
+void somethingToCall();
+
+ static constexpr bool isConstExprConfigValue() { return true; }
+
+ int test_const_expr_config_value() {
+ if (isConstExprConfigValue()) {
+ somethingToCall();
+ return 0;
+ }
+ somethingToCall(); // no-warning
+ return 1;
+ }
+ int test_const_expr_config_value_2() {
+ if (!isConstExprConfigValue()) {
+ somethingToCall(); // no-warning
+ return 0;
+ }
+ somethingToCall();
+ return 1;
+ }
+
More information about the cfe-commits
mailing list