aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 4a7be55366..003be8289f 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1397,7 +1397,9 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) {
// __module_private__ is propagated to later declarations.
if (Old->isModulePrivate())
New->setModulePrivate();
-
+ else if (New->isModulePrivate())
+ diagnoseModulePrivateRedeclaration(New, Old);
+
if (getLangOptions().Microsoft)
return;
@@ -1966,7 +1968,9 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) {
// __module_private__ is propagated to later declarations.
if (Old->isModulePrivate())
New->setModulePrivate();
-
+ else if (New->isModulePrivate())
+ diagnoseModulePrivateRedeclaration(New, Old);
+
// Merge attributes from the parameters. These can mismatch with K&R
// declarations.
if (New->getNumParams() == Old->getNumParams())
@@ -2152,6 +2156,8 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
// __module_private__ is propagated to later declarations.
if (Old->isModulePrivate())
New->setModulePrivate();
+ else if (New->isModulePrivate())
+ diagnoseModulePrivateRedeclaration(New, Old);
// Variables with external linkage are analyzed in FinalizeDeclaratorGroup.
@@ -7139,7 +7145,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
SourceLocation KWLoc, CXXScopeSpec &SS,
IdentifierInfo *Name, SourceLocation NameLoc,
AttributeList *Attr, AccessSpecifier AS,
- bool IsModulePrivate,
+ SourceLocation ModulePrivateLoc,
MultiTemplateParamsArg TemplateParameterLists,
bool &OwnedDecl, bool &IsDependent,
bool ScopedEnum, bool ScopedEnumUsesClassTag,
@@ -7179,7 +7185,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
DeclResult Result = CheckClassTemplate(S, TagSpec, TUK, KWLoc,
SS, Name, NameLoc, Attr,
TemplateParams, AS,
- IsModulePrivate,
+ ModulePrivateLoc,
TemplateParameterLists.size() - 1,
(TemplateParameterList**) TemplateParameterLists.release());
return Result.get();
@@ -7744,9 +7750,13 @@ CreateNewDecl:
if (PrevDecl && PrevDecl->isModulePrivate())
New->setModulePrivate();
- else if (IsModulePrivate)
- New->setModulePrivate();
-
+ else if (ModulePrivateLoc.isValid()) {
+ if (PrevDecl && !PrevDecl->isModulePrivate())
+ diagnoseModulePrivateRedeclaration(New, PrevDecl, ModulePrivateLoc);
+ else
+ New->setModulePrivate();
+ }
+
// If this is a specialization of a member class (of a class template),
// check the specialization.
if (isExplicitSpecialization && CheckMemberSpecialization(New, Previous))
@@ -9417,6 +9427,20 @@ DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc,
return DeclResult((Decl *)0);
}
+void
+Sema::diagnoseModulePrivateRedeclaration(NamedDecl *New, NamedDecl *Old,
+ SourceLocation ModulePrivateKeyword) {
+ assert(!Old->isModulePrivate() && "Old is module-private!");
+
+ Diag(New->getLocation(), diag::err_module_private_follows_public)
+ << New->getDeclName() << SourceRange(ModulePrivateKeyword);
+ Diag(Old->getLocation(), diag::note_previous_declaration)
+ << Old->getDeclName();
+
+ // Drop the __module_private__ from the new declaration, since it's invalid.
+ New->setModulePrivate(false);
+}
+
void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,
SourceLocation PragmaLoc,
SourceLocation NameLoc) {