Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -1424,6 +1424,12 @@ } static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) { + // FIXME: Workaround to make preferred_name to not block the ODR checks + // for Modules. See https://github.com/llvm/llvm-project/issues/56490 for + // details. + if (S.getLangOpts().CPlusPlusModules && D->getOwningModule()) + return; + 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,40 @@ +// 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 +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm -verify -fsyntax-only +// + +//--- foo.h +template +class foo_templ; + +typedef foo_templ foo; + +template +class +__attribute__((__preferred_name__(foo))) +foo_templ { +public: + foo_templ() {} +}; + +inline foo_templ bar() +{ + return foo_templ(); +} + +//--- A.cppm +module; +#include "foo.h" +export module A; + +//--- Use.cppm +// expected-no-diagnostics +module; +#include "foo.h" +export module Use; +import A;