[cfe-commits] r90727 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplateInstantiate.cpp test/CodeGenCXX/default-constructor-template-member.cpp test/Sema/nested-redef.c test/SemaObjC/ivar-sem-check-1.m
Eli Friedman
eli.friedman at gmail.com
Sun Dec 6 16:22:10 PST 2009
Author: efriedma
Date: Sun Dec 6 18:22:08 2009
New Revision: 90727
URL: http://llvm.org/viewvc/llvm-project?rev=90727&view=rev
Log:
Move RequireCompleteType requirement for fields early into ActOnField so that
subsequent code which depends on a complete type does the right thing.
Added:
cfe/trunk/test/CodeGenCXX/default-constructor-template-member.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/Sema/nested-redef.c
cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=90727&r1=90726&r2=90727&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Dec 6 18:22:08 2009
@@ -5044,9 +5044,14 @@
T = Context.IntTy;
}
+ QualType EltTy = Context.getBaseElementType(T);
+ if (!EltTy->isDependentType() &&
+ RequireCompleteType(Loc, EltTy, diag::err_field_incomplete))
+ InvalidDecl = true;
+
// C99 6.7.2.1p8: A member of a structure or union may have any type other
// than a variably modified type.
- if (T->isVariablyModifiedType()) {
+ if (!InvalidDecl && T->isVariablyModifiedType()) {
bool SizeIsNegative;
QualType FixedTy = TryToFixInvalidVariablyModifiedType(T, Context,
SizeIsNegative);
@@ -5063,13 +5068,15 @@
}
// Fields can not have abstract class types
- if (RequireNonAbstractType(Loc, T, diag::err_abstract_type_in_decl,
- AbstractFieldType))
+ if (!InvalidDecl && RequireNonAbstractType(Loc, T,
+ diag::err_abstract_type_in_decl,
+ AbstractFieldType))
InvalidDecl = true;
bool ZeroWidth = false;
// If this is declared as a bit-field, check the bit-field.
- if (BitWidth && VerifyBitField(Loc, II, T, BitWidth, &ZeroWidth)) {
+ if (!InvalidDecl && BitWidth &&
+ VerifyBitField(Loc, II, T, BitWidth, &ZeroWidth)) {
InvalidDecl = true;
DeleteExpr(BitWidth);
BitWidth = 0;
@@ -5088,8 +5095,6 @@
}
if (getLangOptions().CPlusPlus) {
- QualType EltTy = Context.getBaseElementType(T);
-
CXXRecordDecl* CXXRecord = cast<CXXRecordDecl>(Record);
if (!T->isPODType())
@@ -5432,8 +5437,10 @@
// If the field is already invalid for some reason, don't emit more
// diagnostics about it.
- if (FD->isInvalidDecl())
+ if (FD->isInvalidDecl()) {
+ EnclosingDecl->setInvalidDecl();
continue;
+ }
// C99 6.7.2.1p2:
// A structure or union shall not contain a member with
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=90727&r1=90726&r2=90727&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sun Dec 6 18:22:08 2009
@@ -1060,10 +1060,10 @@
Member != MemberEnd; ++Member) {
Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs);
if (NewMember) {
- if (NewMember->isInvalidDecl()) {
- Invalid = true;
- } else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember))
+ if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember))
Fields.push_back(DeclPtrTy::make(Field));
+ else if (NewMember->isInvalidDecl())
+ Invalid = true;
} else {
// FIXME: Eventually, a NULL return will mean that one of the
// instantiations was a semantic disaster, and we'll want to set Invalid =
Added: cfe/trunk/test/CodeGenCXX/default-constructor-template-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/default-constructor-template-member.cpp?rev=90727&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/default-constructor-template-member.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/default-constructor-template-member.cpp Sun Dec 6 18:22:08 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm %s -o - | FileCheck %s
+
+template <class T> struct A { A(); };
+struct B { A<int> x; };
+void a() {
+ B b;
+}
+// CHECK: call void @_ZN1BC1Ev
+// CHECK: define linkonce_odr void @_ZN1BC1Ev
+// CHECK: call void @_ZN1AIiEC1Ev
Modified: cfe/trunk/test/Sema/nested-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nested-redef.c?rev=90727&r1=90726&r2=90727&view=diff
==============================================================================
--- cfe/trunk/test/Sema/nested-redef.c (original)
+++ cfe/trunk/test/Sema/nested-redef.c Sun Dec 6 18:22:08 2009
@@ -1,6 +1,7 @@
// RUN: clang-cc -fsyntax-only -verify %s
struct X { // expected-note{{previous definition is here}}
- struct X { } x; // expected-error{{nested redefinition of 'X'}}
+ struct X { } x; // expected-error{{nested redefinition of 'X'}} \
+ // expected-error{{field has incomplete type}}
};
struct Y { };
Modified: cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-sem-check-1.m?rev=90727&r1=90726&r2=90727&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-sem-check-1.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-sem-check-1.m Sun Dec 6 18:22:08 2009
@@ -9,7 +9,8 @@
int arr[]; // expected-error {{field has incomplete type}}
struct S IC; // expected-error {{field has incomplete type}}
struct T { // expected-note {{previous definition is here}}
- struct T {} X; // expected-error {{nested redefinition of 'T'}}
+ struct T {} X; // expected-error {{nested redefinition of 'T'}} \
+ // expected-error {{field has incomplete type}}
}YYY;
FOO BADFUNC; // expected-error {{field 'BADFUNC' declared as a function}}
int kaka; // expected-note {{previous declaration is here}}
More information about the cfe-commits
mailing list