]> granicus.if.org Git - clang/commitdiff
If x is an invalid field decl, don't construct an expression for P->x,
authorChris Lattner <sabre@nondot.org>
Fri, 13 Feb 2009 22:08:30 +0000 (22:08 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 13 Feb 2009 22:08:30 +0000 (22:08 +0000)
just silently return an error to avoid bogus diagnostics.

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

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

index 628f233d6813c927f64d92618986c5418770fbe0..6b82eadaea2cff7ffdf01d24b30379d50e921cc4 100644 (file)
@@ -1571,6 +1571,12 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
     } else
       MemberDecl = Result;
 
+    // If the decl being referenced had an error, return an error for this
+    // sub-expr without emitting another error, in order to avoid cascading
+    // error cases.
+    if (MemberDecl->isInvalidDecl())
+      return ExprError();
+
     if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
       // We may have found a field within an anonymous union or struct
       // (C++ [class.union]).
@@ -1623,6 +1629,12 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
   // (*Obj).ivar.
   if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
     if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member)) {
+      // If the decl being referenced had an error, return an error for this
+      // sub-expr without emitting another error, in order to avoid cascading
+      // error cases.
+      if (IV->isInvalidDecl())
+        return ExprError();
+      
       ObjCIvarRefExpr *MRef= new (Context) ObjCIvarRefExpr(IV, IV->getType(), 
                                                  MemberLoc, BaseExpr,
                                                  OpKind == tok::arrow);
index db2daf1f7ca875b465a143ad3b3c64a220db7861..4ddb976eb2e0bd8a04c94f40c9033b91487313ec 100644 (file)
@@ -57,3 +57,10 @@ int test9(struct f *P) {
   return R;
 }
 
+// PR3562
+void test10(int n,...) {
+  struct S {
+    double          a[n];  // expected-error {{fields must have a constant size}}
+  }               s;
+  double x = s.a[0];  // should not get another error here.
+}