]> granicus.if.org Git - clang/commitdiff
C's comma operator performs lvalue conversion on both its operands;
authorJohn McCall <rjmccall@apple.com>
Tue, 12 Oct 2010 07:14:40 +0000 (07:14 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 12 Oct 2010 07:14:40 +0000 (07:14 +0000)
require them to have complete types.

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

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

index 52ab62be020fe7249261564d34dc1b8c52135383..514d9ba3f2fa7bdcf1d0246765398c7298486172 100644 (file)
@@ -6164,13 +6164,18 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS,
 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();
 }
index 56a52bed1bc364b3bb696a1fdbac28171040b8ca..d6e17ff6ecc9f7025e164a0faf579b4e8963fe6d 100644 (file)
@@ -150,3 +150,10 @@ int test20(int x) {
   // 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}}
+}