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.
This commit is contained in:
Richard Smith 2020-09-28 17:21:42 -07:00
parent 6fd8c69049
commit c375635d05
2 changed files with 11 additions and 1 deletions

View File

@ -9644,7 +9644,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
// In C builtins get merged with implicitly lazily created declarations.
// In C++ we need to check if it's a builtin and add the BuiltinAttr here.
if (getLangOpts().CPlusPlus) {
if (getLangOpts().CPlusPlus &&
NewFD->getDeclContext()->getRedeclContext()->isFileContext()) {
if (IdentifierInfo *II = Previous.getLookupName().getAsIdentifierInfo()) {
if (unsigned BuiltinID = II->getBuiltinID()) {
if (NewFD->getLanguageLinkage() == CLanguageLinkage) {

View File

@ -171,3 +171,12 @@ union {
} x;
} x;
} static_member_3;
// Ensure we don't compute the linkage of a member function just because it
// happens to have the same name as a builtin.
namespace BuiltinName {
// Note that this is not an error: we didn't trigger linkage computation in this example.
typedef struct { // expected-warning {{anonymous non-C-compatible type}}
void memcpy(); // expected-note {{due to this member}}
} A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
}