[cfe-commits] r66701 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp SemaDeclCXX.cpp SemaTemplateInstantiate.cpp
Douglas Gregor
dgregor at apple.com
Wed Mar 11 13:50:30 PDT 2009
Author: dgregor
Date: Wed Mar 11 15:50:30 2009
New Revision: 66701
URL: http://llvm.org/viewvc/llvm-project?rev=66701&view=rev
Log:
Make sure that we set the access specifier for an instantiated FieldDecl, and that the aggregate and POD flags for an instantiated class template are updated based on instantiation of a FieldDecl
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=66701&r1=66700&r2=66701&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Mar 11 15:50:30 2009
@@ -369,12 +369,13 @@
Declarator &D, ExprTy *BitfieldWidth);
FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
- Declarator &D, Expr *BitfieldWidth);
+ Declarator &D, Expr *BitfieldWidth,
+ AccessSpecifier AS);
FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
RecordDecl *Record, SourceLocation Loc,
bool Mutable, Expr *BitfieldWidth,
- NamedDecl *PrevDecl,
+ AccessSpecifier AS, NamedDecl *PrevDecl,
Declarator *D = 0);
virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66701&r1=66700&r2=66701&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 11 15:50:30 2009
@@ -3253,14 +3253,16 @@
SourceLocation DeclStart,
Declarator &D, ExprTy *BitfieldWidth) {
return HandleField(S, static_cast<RecordDecl*>(TagD), DeclStart, D,
- static_cast<Expr*>(BitfieldWidth));
+ static_cast<Expr*>(BitfieldWidth),
+ AS_public);
}
/// HandleField - Analyze a field of a C struct or a C++ data member.
///
FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
SourceLocation DeclStart,
- Declarator &D, Expr *BitWidth) {
+ Declarator &D, Expr *BitWidth,
+ AccessSpecifier AS) {
IdentifierInfo *II = D.getIdentifier();
SourceLocation Loc = DeclStart;
if (II) Loc = D.getIdentifierLoc();
@@ -3277,7 +3279,7 @@
FieldDecl *NewFD
= CheckFieldDecl(II, T, Record, Loc,
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_mutable,
- BitWidth, PrevDecl, &D);
+ BitWidth, AS, PrevDecl, &D);
if (NewFD->isInvalidDecl() && PrevDecl) {
// Don't introduce NewFD into scope; there's already something
// with the same name in the same scope.
@@ -3302,7 +3304,7 @@
FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
RecordDecl *Record, SourceLocation Loc,
bool Mutable, Expr *BitWidth,
- NamedDecl *PrevDecl,
+ AccessSpecifier AS, NamedDecl *PrevDecl,
Declarator *D) {
IdentifierInfo *II = Name.getAsIdentifierInfo();
bool InvalidDecl = false;
@@ -3364,6 +3366,19 @@
if (InvalidDecl)
NewFD->setInvalidDecl();
+ NewFD->setAccess(AS);
+
+ // C++ [dcl.init.aggr]p1:
+ // An aggregate is an array or a class (clause 9) with [...] no
+ // private or protected non-static data members (clause 11).
+ // A POD must be an aggregate.
+ if (getLangOptions().CPlusPlus &&
+ (AS == AS_private || AS == AS_protected)) {
+ CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record);
+ CXXRecord->setAggregate(false);
+ CXXRecord->setPOD(false);
+ }
+
return NewFD;
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=66701&r1=66700&r2=66701&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Mar 11 15:50:30 2009
@@ -547,7 +547,8 @@
Decl *Member;
if (isInstField) {
- Member = HandleField(S, cast<CXXRecordDecl>(CurContext), Loc, D, BitWidth);
+ Member = HandleField(S, cast<CXXRecordDecl>(CurContext), Loc, D, BitWidth,
+ AS);
assert(Member && "HandleField never returns null");
} else {
Member = static_cast<Decl*>(ActOnDeclarator(S, D, LastInGroup));
@@ -581,22 +582,12 @@
BitWidth = 0;
Member->setInvalidDecl();
}
+
+ Member->setAccess(AS);
}
assert((Name || isInstField) && "No identifier for non-field ?");
- Member->setAccess(AS);
-
- // C++ [dcl.init.aggr]p1:
- // An aggregate is an array or a class (clause 9) with [...] no
- // private or protected non-static data members (clause 11).
- // A POD must be an aggregate.
- if (isInstField && (AS == AS_private || AS == AS_protected)) {
- CXXRecordDecl *Record = cast<CXXRecordDecl>(CurContext);
- Record->setAggregate(false);
- Record->setPOD(false);
- }
-
if (DS.isVirtualSpecified()) {
if (!isFunc || DS.getStorageClassSpec() == DeclSpec::SCS_static) {
Diag(DS.getVirtualSpecLoc(), diag::err_virtual_non_function);
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=66701&r1=66700&r2=66701&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Mar 11 15:50:30 2009
@@ -718,6 +718,7 @@
Field->getLocation(),
Field->isMutable(),
Field->getBitWidth(),
+ Field->getAccess(),
0);
if (New) {
ClassTemplateSpec->addDecl(New);
More information about the cfe-commits
mailing list