From b17a3aa4d70428d5ef4a74102db96476ee9b4484 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 20 Mar 2014 06:07:35 +0000 Subject: [PATCH] [-Wunreachable-code] constexpr functions can be used as configuration values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204308 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ReachableCode.cpp | 5 +++++ test/SemaCXX/warn-unreachable.cpp | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index c79a94b820c..ffe576cd052 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -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(cast(S)->getCalleeDecl()); + return Callee ? Callee->isConstexpr() : false; + } case Stmt::DeclRefExprClass: { const DeclRefExpr *DR = cast(S); const ValueDecl *D = DR->getDecl(); diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index abab966c660..9db75926d23 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -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(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; + } +