]> granicus.if.org Git - clang/commitdiff
PR16727: don't try to evaluate a potentially value-dependent expression when
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 19 Aug 2013 22:06:05 +0000 (22:06 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 19 Aug 2013 22:06:05 +0000 (22:06 +0000)
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
test/SemaCXX/parentheses.cpp [new file with mode: 0644]

index 67bfffcd4188ce57e1aa7d96b7d53e7aef57ba77..d0fb643eb354765254e7336111b320cc32985501 100644 (file)
@@ -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 (file)
index 0000000..b430b25
--- /dev/null
@@ -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}}
+}