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

John McCall rjmccall at apple.com
Tue Oct 12 00:14:41 PDT 2010


Author: rjmccall
Date: Tue Oct 12 02:14:40 2010
New Revision: 116297

URL: http://llvm.org/viewvc/llvm-project?rev=116297&view=rev
Log:
C's comma operator performs lvalue conversion on both its operands;
require them to have complete types.


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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=116297&r1=116296&r2=116297&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct 12 02:14:40 2010
@@ -6164,13 +6164,18 @@
 QualType Sema::CheckCommaOperands(Expr *LHS, Expr *&RHS, SourceLocation Loc) {
   DiagnoseUnusedExprResult(LHS);
 
-  // Comma performs lvalue conversion (C99 6.3.2.1), but not unary conversions.
-  // C++ does not perform this conversion (C++ [expr.comma]p1).
-  if (!getLangOptions().CPlusPlus)
-    DefaultFunctionArrayLvalueConversion(RHS);
+  // C's comma performs lvalue conversion (C99 6.3.2.1) on both its
+  // operands, but not unary promotions.
+  // C++'s comma does not do any conversions at all (C++ [expr.comma]p1).
+  if (!getLangOptions().CPlusPlus) {
+    DefaultFunctionArrayLvalueConversion(LHS);
+    if (!LHS->getType()->isVoidType())
+      RequireCompleteType(Loc, LHS->getType(), diag::err_incomplete_type);
 
-  // FIXME: Check that RHS type is complete in C mode (it's legal for it to be
-  // incomplete in C++).
+    DefaultFunctionArrayLvalueConversion(RHS);
+    if (!RHS->getType()->isVoidType())
+      RequireCompleteType(Loc, RHS->getType(), diag::err_incomplete_type);
+  }
 
   return RHS->getType();
 }

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=116297&r1=116296&r2=116297&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Tue Oct 12 02:14:40 2010
@@ -150,3 +150,10 @@
   // no warning, this is an idiom for "true" in old C style.
   return x && (signed char)1;
 }
+
+struct Test21; // expected-note 2 {{forward declaration}}
+void test21(volatile struct Test21 *ptr) {
+  void test21_help(void);
+  (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}}
+}





More information about the cfe-commits mailing list