]> granicus.if.org Git - clang/commitdiff
Make sure that we set the access specifier for an instantiated FieldDecl, and that...
authorDouglas Gregor <dgregor@apple.com>
Wed, 11 Mar 2009 20:50:30 +0000 (20:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 11 Mar 2009 20:50:30 +0000 (20:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66701 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplateInstantiate.cpp

index 1a66cc032420d450efff1d44053374931154b0a1..8f033197e4442ab2bb8356fc32b7b12bd6113cce 100644 (file)
@@ -369,12 +369,13 @@ public:
                              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,
index f77d1d8845f8684c5ed87d70904d6d5f550e0837..2e033bf907ac8c7435d1da3d1d09d8a1135aee64 100644 (file)
@@ -3253,14 +3253,16 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagD,
                                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 *Sema::HandleField(Scope *S, RecordDecl *Record,
   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::HandleField(Scope *S, RecordDecl *Record,
 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 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
   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;
 }
 
index bedea3a7cd7096d3c33c9a173f1b2eb7c4a33c5f..0ea501d993dae3a09fbebf735c0bd070eabd049f 100644 (file)
@@ -547,7 +547,8 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
 
   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 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
       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);
index 5800ab9265a1918b7767dc877309b47bf1d4dfd3..343c00b7452d3fa1d31ba422d841dc541cee0321 100644 (file)
@@ -718,6 +718,7 @@ Sema::InstantiateClassTemplateSpecialization(
                                       Field->getLocation(),
                                       Field->isMutable(),
                                       Field->getBitWidth(),
+                                      Field->getAccess(),
                                       0);
       if (New) {
         ClassTemplateSpec->addDecl(New);