Skip to content

Commit

Permalink
[-Wunreachable-code] constexpr functions can be used as configuration…
Browse files Browse the repository at this point in the history
… values.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204308 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Mar 20, 2014
1 parent a80944a commit b17a3aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Analysis/ReachableCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ static bool isConfigurationValue(const Stmt *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();
Expand Down
23 changes: 22 additions & 1 deletion test/SemaCXX/warn-unreachable.cpp
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -234,3 +234,24 @@ Frobozz test_return_object_control_flow(int flag) {
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;
}

0 comments on commit b17a3aa

Please sign in to comment.