Skip to content

Commit 1ccbc2e

Browse files
committed
[Sema] Don't drop weak_import from a declaration that follows a
declaration directly contained in a linkage-specification Only drop it if the declaration follows a definition. I believe this is what 33e0226 was trying to do. rdar://61865848
1 parent 6f31cf5 commit 1ccbc2e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,8 +4613,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
46134613
mergeDeclAttributes(New, Old);
46144614
// Warn if an already-declared variable is made a weak_import in a subsequent
46154615
// declaration
4616-
if (New->hasAttr<WeakImportAttr>() &&
4617-
Old->getStorageClass() == SC_None &&
4616+
if (New->hasAttr<WeakImportAttr>() && Old->isThisDeclarationADefinition() &&
46184617
!Old->hasAttr<WeakImportAttr>()) {
46194618
Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
46204619
Diag(Old->getLocation(), diag::note_previous_declaration);

clang/test/SemaCXX/attr-weak.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ constexpr bool weak_method_is_non_null = &WithWeakMember::weak_method != nullptr
5555
// virtual member function is present.
5656
constexpr bool virtual_weak_method_is_non_null = &WithWeakMember::virtual_weak_method != nullptr; // expected-error {{must be initialized by a constant expression}}
5757
// expected-note@-1 {{comparison against pointer to weak member 'WithWeakMember::virtual_weak_method' can only be performed at runtime}}
58+
59+
// Check that no warnings are emitted.
60+
extern "C" int g0;
61+
extern int g0 __attribute__((weak_import));
62+
63+
extern "C" int g1 = 0; // expected-note {{previous definition is here}}
64+
extern int g1 __attribute__((weak_import)); // expected-warning {{attribute declaration must precede definition}}

0 commit comments

Comments
 (0)