Author: Richard Smith Date: 2020-09-28T17:22:40-07:00 New Revision: c375635d05f6f10c7c95ecc74a0569213d176d8e
URL: https://github.com/llvm/llvm-project/commit/c375635d05f6f10c7c95ecc74a0569213d176d8e DIFF: https://github.com/llvm/llvm-project/commit/c375635d05f6f10c7c95ecc74a0569213d176d8e.diff LOG: 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. Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/SemaCXX/anonymous-struct.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 2599e3b46e4e..aff49b7ddb90 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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) { diff --git a/clang/test/SemaCXX/anonymous-struct.cpp b/clang/test/SemaCXX/anonymous-struct.cpp index 333b8f724f4e..f85b00bc8bce 100644 --- a/clang/test/SemaCXX/anonymous-struct.cpp +++ b/clang/test/SemaCXX/anonymous-struct.cpp @@ -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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits