https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122625
Bug ID: 122625
Summary: Link error when using std::format in module
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d7d1cd at mail dot ru
Target Milestone: ---
The module contains the following code:
module;
#include <format>
export module M;
export template <typename... Args>
auto foo(std::format_string<Args...> && format, Args &&... args) {
return std::format(std::move(format), std::forward<Args>(args)...);
}
The module is imported and the function is called:
import M;
int main() {
auto a = foo("{}", 42);
}
This code compiles successfully, but linking fails with errors:
gnu/bin/ld: CMakeFiles/app.dir/main.cc.o: in function `std::span<char,
18446744073709551615ul>::span<12ul>(char (&) [12ul])':
main.cc:(.text._ZNSt4spanIcLm18446744073709551615EEC2ILm12EEERAT__c[_ZNSt4spanIcLm18446744073709551615EEC5ILm12EEERAT__c]+0x25):
undefined reference to `std::span<char, 18446744073709551615ul>::__v<12ul>'
gnu/bin/ld: CMakeFiles/app.dir/main.cc.o: in function `std::span<char,
18446744073709551615ul>::span<256ul>(char (&) [256ul])':
main.cc:(.text._ZNSt4spanIcLm18446744073709551615EEC2ILm256EEERAT__c[_ZNSt4spanIcLm18446744073709551615EEC5ILm256EEERAT__c]+0x25):
undefined reference to `std::span<char, 18446744073709551615ul>::__v<256ul>'
The error can be reproduced here: https://godbolt.org/z/86Pqo898q . It's
important to note that the error only occurs on the trunk version. It doesn't
occur on versions 14.2 - 15.2.