https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121238
--- Comment #7 from Omer Ozarslan <omerfaruko at gmail dot com> ---
Hi. I could isolate this to around __parse_integer (__from_chars_alnum?) based
on above snippets.
Please also take a look at Bug 121254 Comment 4 which is likely related.
Removing the template from parse_integer makes it work.
==> format.hpp <==
#include <charconv>
#ifdef TEMPLATES
template <typename = void>
#else
inline
#endif
bool parse_integer(const char *first, const char *last) {
const char *__start = first;
short val = 0;
if (std::__detail::__from_chars_alnum<true, short>(first, last, val, 10) &&
first != __start)
return true;
return false;
}
inline bool works() {
const char fmt[] = "5";
return parse_integer(fmt, fmt + 1);
}
==> test.sh <==
#!/bin/bash
set -ex
rm -rf gcm.cache
CXX=/opt/gcc-16-20250720/bin/g++
CXXFLAGS="-g -fmodules -std=c++20 -w -Wfatal-errors -Werror=template-body"
cat <<eof >mod.hpp
#include "format.hpp"
eof
cat <<eof >test.cpp
#include "format.hpp"
#ifdef MODULES
import "mod.hpp";
#endif
int main() {
return works() ? 0 : 1;
}
eof
# no modules still works
$CXX $CXXFLAGS test.cpp -o a.out
./a.out
# modules fails with template
$CXX $CXXFLAGS -DMODULES -DTEMPLATES mod.hpp test.cpp -o b.out
! ./b.out || exit 1
# modules without template still works
$CXX $CXXFLAGS -DMODULES mod.hpp test.cpp -o c.out
./c.out