[cfe-commits] r120895 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/exprs.c test/SemaCXX/condition.cpp

John McCall rjmccall at apple.com
Fri Dec 3 22:09:13 PST 2010


Author: rjmccall
Date: Sat Dec  4 00:09:13 2010
New Revision: 120895

URL: http://llvm.org/viewvc/llvm-project?rev=120895&view=rev
Log:
When deciding whether to complain about the type of a boolean condition, use
the type of the expression *after* array/function decay.


Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/exprs.c
    cfe/trunk/test/SemaCXX/condition.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=120895&r1=120894&r2=120895&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Dec  4 00:09:13 2010
@@ -9037,12 +9037,12 @@
       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();

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=120895&r1=120894&r2=120895&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Sat Dec  4 00:09:13 2010
@@ -157,3 +157,12 @@
   (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;
+}

Modified: cfe/trunk/test/SemaCXX/condition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/condition.cpp?rev=120895&r1=120894&r2=120895&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/condition.cpp Sat Dec  4 00:09:13 2010
@@ -42,3 +42,12 @@
   if (int *ip = ip) {
   }
 }
+
+// Make sure we do function/array decay.
+void test3() {
+  if ("help")
+    (void) 0;
+
+  if (test3)
+    (void) 0;
+}





More information about the cfe-commits mailing list