]> granicus.if.org Git - clang/commitdiff
When deciding whether to complain about the type of a boolean condition, use
authorJohn McCall <rjmccall@apple.com>
Sat, 4 Dec 2010 06:09:13 +0000 (06:09 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 4 Dec 2010 06:09:13 +0000 (06:09 +0000)
the type of the expression *after* array/function decay.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120895 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/exprs.c
test/SemaCXX/condition.cpp

index 8b29667bae11afd0eb3fdb7816a98e5e77728e9a..cf17566d41a6ace3781905361295ab738af1f1ec 100644 (file)
@@ -9037,12 +9037,12 @@ bool Sema::CheckBooleanCondition(Expr *&E, SourceLocation Loc) {
       return Diag(E->getLocStart(), diag::err_invalid_use_of_bound_member_func)
         << E->getSourceRange();
 
-    QualType T = E->getType();
-
     if (getLangOptions().CPlusPlus)
       return CheckCXXBooleanCondition(E); // C++ 6.4p4
 
     DefaultFunctionArrayLvalueConversion(E);
+
+    QualType T = E->getType();
     if (!T->isScalarType()) // C99 6.8.4.1p1
       return Diag(Loc, diag::err_typecheck_statement_requires_scalar)
                << T << E->getSourceRange();
index d6e17ff6ecc9f7025e164a0faf579b4e8963fe6d..e88f7fc08bce2621e6b7ee3c3496d4b3ea505c8c 100644 (file)
@@ -157,3 +157,12 @@ void test21(volatile struct Test21 *ptr) {
   (test21_help(), *ptr); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
   (*ptr, test21_help()); // expected-error {{incomplete type 'struct Test21' where a complete type is required}}
 }
+
+// Make sure we do function/array decay.
+void test22() {
+  if ("help")
+    (void) 0;
+
+  if (test22)
+    (void) 0;
+}
index daa86f62fcf018087cfd2b3cdb4b39dc77a86bcf..61d1762be85f241379822cb933aaa8ae24fa51c7 100644 (file)
@@ -42,3 +42,12 @@ void test2() {
   if (int *ip = ip) {
   }
 }
+
+// Make sure we do function/array decay.
+void test3() {
+  if ("help")
+    (void) 0;
+
+  if (test3)
+    (void) 0;
+}