From: Douglas Gregor Date: Fri, 9 Sep 2011 18:32:39 +0000 (+0000) Subject: Propagate __module_private__ from previous declarations to later X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6311d2bb3db1ec1064f45a14983ae5806adc676a;p=clang Propagate __module_private__ from previous declarations to later declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 881fb86a78..4a7be55366 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1394,6 +1394,10 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) { if (TypedefNameDecl *Typedef = dyn_cast(Old)) New->setPreviousDeclaration(Typedef); + // __module_private__ is propagated to later declarations. + if (Old->isModulePrivate()) + New->setModulePrivate(); + if (getLangOptions().Microsoft) return; @@ -1959,6 +1963,10 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) { if (Old->isPure()) New->setPure(); + // __module_private__ is propagated to later declarations. + if (Old->isModulePrivate()) + New->setModulePrivate(); + // Merge attributes from the parameters. These can mismatch with K&R // declarations. if (New->getNumParams() == Old->getNumParams()) @@ -2141,6 +2149,10 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { return New->setInvalidDecl(); } + // __module_private__ is propagated to later declarations. + if (Old->isModulePrivate()) + New->setModulePrivate(); + // Variables with external linkage are analyzed in FinalizeDeclaratorGroup. // FIXME: The test for external storage here seems wrong? We still @@ -5242,6 +5254,10 @@ void Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, NewTemplateDecl->setMemberSpecialization(); assert(OldTemplateDecl->isMemberSpecialization()); } + + if (OldTemplateDecl->isModulePrivate()) + NewTemplateDecl->setModulePrivate(); + } else { if (isa(NewFD)) // Set access for out-of-line definitions NewFD->setAccess(OldDecl->getAccess()); @@ -7726,7 +7742,9 @@ CreateNewDecl: AddMsStructLayoutForRecord(RD); } - if (IsModulePrivate) + if (PrevDecl && PrevDecl->isModulePrivate()) + New->setModulePrivate(); + else if (IsModulePrivate) New->setModulePrivate(); // If this is a specialization of a member class (of a class template), diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 80e972fae7..eb199aced4 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -945,7 +945,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, // definition, as part of error recovery? return true; } - } + } } else if (PrevDecl && PrevDecl->isTemplateParameter()) { // Maybe we will complain about the shadowed template parameter. DiagnoseTemplateParameterShadow(NameLoc, PrevDecl); @@ -999,8 +999,10 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, DeclarationName(Name), TemplateParams, NewClass, PrevClassTemplate); NewClass->setDescribedClassTemplate(NewTemplate); - - if (IsModulePrivate) + + if (PrevClassTemplate && PrevClassTemplate->isModulePrivate()) { + NewTemplate->setModulePrivate(); + } else if (IsModulePrivate) NewTemplate->setModulePrivate(); // Build the type for the class template declaration now. diff --git a/test/Modules/module-private.cpp b/test/Modules/module-private.cpp index 419946e8a5..689abd746a 100644 --- a/test/Modules/module-private.cpp +++ b/test/Modules/module-private.cpp @@ -5,7 +5,9 @@ #if defined(MODULE_LEFT) -__module_private__ struct HiddenStruct { +__module_private__ struct HiddenStruct; + +struct HiddenStruct { }; @@ -15,15 +17,23 @@ template __module_private__ void f1(T*); template -__module_private__ class vector { +void f1(T*); + +template +__module_private__ class vector; + +template +class vector { }; vector vec_float; typedef __module_private__ int Integer; +typedef int Integer; #elif defined(MODULE_RIGHT) __module_private__ double &f0(double); +double &f0(double); __module_private__ int hidden_var;