diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-08-19 22:06:05 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-08-19 22:06:05 +0000 |
| commit | a6c8703e5be73be2f04437285cc63d30999b45ce (patch) | |
| tree | ae82ab2944d161ebb53d68218d8b9720f2400aed | |
| parent | 28c23706029056d2f4e231ccf58b8380312b164f (diff) | |
| download | bcm5719-llvm-a6c8703e5be73be2f04437285cc63d30999b45ce.tar.gz bcm5719-llvm-a6c8703e5be73be2f04437285cc63d30999b45ce.zip | |
PR16727: don't try to evaluate a potentially value-dependent expression when
checking for missing parens in &&/|| expressions.
llvm-svn: 188716
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaCXX/parentheses.cpp | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 67bfffcd418..d0fb643eb35 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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/clang/test/SemaCXX/parentheses.cpp b/clang/test/SemaCXX/parentheses.cpp new file mode 100644 index 00000000000..b430b25e5d6 --- /dev/null +++ b/clang/test/SemaCXX/parentheses.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify %s + +// PR16930, PR16727: +template<class Foo> +bool test(Foo f, int *array) +{ + return false && false || array[f.get()]; // expected-warning {{'&&' within '||'}} expected-note {{parentheses}} +} |

