[Modules] Incorrect ODR checks caused by preferred_name attribute. · Issue #56490 · llvm/llvm-project (original) (raw)

I met an incorrect ODR checks caused by preferred_name. Here is a reduced example.

// string_view.h template class basic_string_view;

typedef basic_string_view string_view;

template class attribute((preferred_name(string_view))) basic_string_view { public: basic_string_view() { } };

inline basic_string_view foo() { return basic_string_view(); } // A.cppm module; #include "string_view.h" export module A;

// Use.cppm module; #include "string_view.h" export module Use; import A;

The input command line is:

clang++ -std=c++20 --precompile A.cppm -o A.pcm clang++ -std=c++20 --precompile Use.cppm -fprebuilt-module-path=. -fsyntax-only

The output would be the incorrect ODR warning:

string_view.h:11:5: error: 'basic_string_view::basic_string_view' from module 'A.' is not present in definition of 'string_view' provided earlier

I've been fighting with the problem for several days. My current process is that when the ASTReader reads the preferred_name attribute, it would read the string_view type and find an existing one. However, the current behavior would create another RecordType for string_view despite there is already one. So here is the problem.