Index: clang/include/clang/Basic/DiagnosticGroups.td =================================================================== --- clang/include/clang/Basic/DiagnosticGroups.td +++ clang/include/clang/Basic/DiagnosticGroups.td @@ -442,6 +442,7 @@ def IncompleteModule : DiagGroup<"incomplete-module", [IncompleteUmbrella, NonModularIncludeInModule]>; def PrivateModule : DiagGroup<"private-module">; +def UnsupportedAttrInModule : DiagGroup<"unsupported-attr-in-module">; def CXX11InlineNamespace : DiagGroup<"c++11-inline-namespace">; def InlineNamespaceReopenedNoninline Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11196,6 +11196,10 @@ "'%0' included multiple times, additional include site in header from module '%1'">; def note_redefinition_include_same_file : Note< "'%0' included multiple times, additional include site here">; + +def warn_preferred_name_in_modules : Warning< + "preferred_name in modules may cause incorrect ODR checks now. Considering to not use it">, + InGroup; } let CategoryName = "Coroutines Issue" in { Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -1424,6 +1424,11 @@ } static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) { + // FIXME: See https://github.com/llvm/llvm-project/issues/56490 for + // details. Remove this one when we fix it actually. + if (S.getLangOpts().CPlusPlusModules && D->getOwningModule()) + S.Diag(D->getLocation(), clang::diag::warn_preferred_name_in_modules); + auto *RD = cast(D); ClassTemplateDecl *CTD = RD->getDescribedClassTemplate(); assert(CTD && "attribute does not appertain to this declaration"); Index: clang/test/Modules/preferred_name.cppm =================================================================== --- /dev/null +++ clang/test/Modules/preferred_name.cppm @@ -0,0 +1,43 @@ +// Tests that the ODR check wouldn't produce false-positive result for preferred_name attribute. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm -verify +// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm -DDISABLE_PREFERRED_NAME +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm -verify -fsyntax-only -DDISABLE_PREFERRED_NAME +// + +//--- foo.h +template +class foo_templ; + +typedef foo_templ foo; + +template +class +#ifndef DISABLE_PREFERRED_NAME +__attribute__((__preferred_name__(foo))) +#endif +foo_templ { +public: + foo_templ() {} +}; + +inline foo_templ bar() +{ + return foo_templ(); +} + +//--- A.cppm +module; +#include "foo.h" // expected-warning@foo.h:11 {{preferred_name in modules may cause incorrect ODR checks now. Considering to not use it}} +export module A; + +//--- Use.cppm +// expected-no-diagnostics +module; +#include "foo.h" +export module Use; +import A;