From: Richard Smith Date: Mon, 19 Aug 2013 22:06:05 +0000 (+0000) Subject: PR16727: don't try to evaluate a potentially value-dependent expression when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=556ef7f8b833d20caf31b80f8c1b5cad2e32ef10;p=clang 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 --- 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}} +}