From 556ef7f8b833d20caf31b80f8c1b5cad2e32ef10 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 19 Aug 2013 22:06:05 +0000 Subject: [PATCH] PR16727: don't try to evaluate a potentially value-dependent expression when checking for missing parens in &&/|| expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188716 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 6 ++++-- test/SemaCXX/parentheses.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/SemaCXX/parentheses.cpp diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 67bfffcd41..d0fb643eb3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9115,14 +9115,16 @@ EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, /// 'true'. static bool EvaluatesAsTrue(Sema &S, Expr *E) { bool Res; - return E->EvaluateAsBooleanCondition(Res, S.getASTContext()) && Res; + return !E->isValueDependent() && + E->EvaluateAsBooleanCondition(Res, S.getASTContext()) && Res; } /// \brief Returns true if the given expression can be evaluated as a constant /// 'false'. static bool EvaluatesAsFalse(Sema &S, Expr *E) { bool Res; - return E->EvaluateAsBooleanCondition(Res, S.getASTContext()) && !Res; + return !E->isValueDependent() && + E->EvaluateAsBooleanCondition(Res, S.getASTContext()) && !Res; } /// \brief Look for '&&' in the left hand of a '||' expr. diff --git a/test/SemaCXX/parentheses.cpp b/test/SemaCXX/parentheses.cpp new file mode 100644 index 0000000000..b430b25e5d --- /dev/null +++ b/test/SemaCXX/parentheses.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify %s + +// PR16930, PR16727: +template +bool test(Foo f, int *array) +{ + return false && false || array[f.get()]; // expected-warning {{'&&' within '||'}} expected-note {{parentheses}} +} -- 2.40.0