[clang][modules] Cannot include and import `string` with libstdc++
Nobody has claimed this yet.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following two translation units
module;
#include <string>
export module b;
namespace std {
export using std::string;
}
#include <string>
import b;
Cause clang to fail to compile with
Step cmake returned: 0
-- The CXX compiler identification is Clang 24.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /app/build
Step build returned: 1
[1/6] Scanning /app/b.cpp for CXX dependencies
[2/6] Scanning /app/c.cpp for CXX dependencies
[3/6] Generating CXX dyndep file CMakeFiles/lib.dir/CXX.dd
[4/6] Building CXX object CMakeFiles/lib.dir/b.cpp.o
[5/6] Building CXX object CMakeFiles/lib.dir/c.cpp.o
FAILED: CMakeFiles/lib.dir/c.cpp.o
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -g -std=c++26 -MD -MT CMakeFiles/lib.dir/c.cpp.o -MF CMakeFiles/lib.dir/c.cpp.o.d @CMakeFiles/lib.dir/c.cpp.o.modmap -o CMakeFiles/lib.dir/c.cpp.o -c /app/c.cpp
In module 'b' imported from /app/c.cpp:3:
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-linux-gnu/bits/c++config.h:377:43: error: cannot add 'abi_tag' attribute in a redeclaration
377 | inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { }
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/basic_string.h:4563:1: note: previous declaration is here
4563 | _GLIBCXX_BEGIN_NAMESPACE_CXX11
| ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-linux-gnu/bits/c++config.h:384:51: note: expanded from macro '_GLIBCXX_BEGIN_NAMESPACE_CXX11'
384 | # define _GLIBCXX_BEGIN_NAMESPACE_CXX11 namespace __cxx11 {
| ^
1 error generated.
ninja: build stopped: subcommand failed.
See it live: https://godbolt.org/z/zaY14ET7x
This reduces down to
namespace a {
inline namespace ai __attribute__((__abi_tag__ ("a"))) { }
}
namespace a {
inline namespace ai {
void af();
}
}
module;
#include "a.hpp"
export module b;
namespace a {
export using a::af;
}
#include "a.hpp"
import b;
void c() {
a::af();
}
See it live: https://godbolt.org/z/s1en115EY
This is a somewhat recent regression, but I'm not at a computer fast enough for me to do the git bisect to find which commit introduced it. This fails on trunk but passes on clang 23.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reduced C++ reproducer involving an abi_tagged inline namespace, then compare its behavior on Clang 23 and trunk. Trace the module import and redeclaration handling that produces the abi_tag error, and add or update a regression test showing that the reproducer compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100