summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fe3b3b4f7c1..daf9f034ac9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2039,12 +2039,17 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
}
mergeDeclAttributes(New, Old, Context);
- // weak_import on current declaration is applied to previous
- // tentative definiton.
+ // Warn if an already-declared variable is made a weak_import in a subsequent declaration
if (New->getAttr<WeakImportAttr>() &&
Old->getStorageClass() == SC_None &&
- !Old->getAttr<WeakImportAttr>())
- Old->addAttr(::new (Context) WeakImportAttr(SourceLocation(), Context));
+ !Old->getAttr<WeakImportAttr>()) {
+ Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ // Remove weak_import attribute on new declaration.
+ // I am just dropping all attributes in curernt decl. We have
+ // already issued a warning, so we are OK.
+ New->dropAttrs();
+ }
// Merge the types.
MergeVarDeclTypes(New, Old);
OpenPOWER on IntegriCloud