Skip to content

Commit c375635

Browse files
committed
Ensure that we don't compute linkage for an anonymous class too early if
it has a member whose name is the same as a builtin. Fixes a regression from the introduction of BuiltinAttr.
1 parent 6fd8c69 commit c375635

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9644,7 +9644,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
96449644

96459645
// In C builtins get merged with implicitly lazily created declarations.
96469646
// In C++ we need to check if it's a builtin and add the BuiltinAttr here.
9647-
if (getLangOpts().CPlusPlus) {
9647+
if (getLangOpts().CPlusPlus &&
9648+
NewFD->getDeclContext()->getRedeclContext()->isFileContext()) {
96489649
if (IdentifierInfo *II = Previous.getLookupName().getAsIdentifierInfo()) {
96499650
if (unsigned BuiltinID = II->getBuiltinID()) {
96509651
if (NewFD->getLanguageLinkage() == CLanguageLinkage) {

clang/test/SemaCXX/anonymous-struct.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,12 @@ union {
171171
} x;
172172
} x;
173173
} static_member_3;
174+
175+
// Ensure we don't compute the linkage of a member function just because it
176+
// happens to have the same name as a builtin.
177+
namespace BuiltinName {
178+
// Note that this is not an error: we didn't trigger linkage computation in this example.
179+
typedef struct { // expected-warning {{anonymous non-C-compatible type}}
180+
void memcpy(); // expected-note {{due to this member}}
181+
} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
182+
}

0 commit comments

Comments
 (0)