Hi,
I am trying to build {fmt} as a C++20 module with GCC-15 (15.0.1 20250214).
I get an error that neither me nor the {fmt} maintainer can make sense
of. We are unsure if it's a code issue or a GCC issue (other compilers
work fine, however they do not implement P1815
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1815r2>).
This is about the following code fragment (os.cc L72
<https://github.com/fmtlib/fmt/blob/master/src/os.cc#L72>, curated from
#ifdefs below), which ends up being included in fmt.cc:
namespace {
// Return type of read and write functions.
using rwresult = ssize_t;
inline std::size_t convert_rwcount(std::size_t count) { return count; }
} // namespace
The compiler reports an error for the line using rwresult = ssize_t; :
/usr/bin/c++ -I/mnt/d/dev/libs/tools/cpp/fmt/include -O3 -DNDEBUG
-std=gnu++20 -fvisibility=hidden -fvisibility-inlines-hidden
-fdiagnostics-color=always -fmodules-ts -MD -MT
CMakeFiles/fmt.dir/src/fmt.cc.o -MF CMakeFiles/fmt.dir/src/fmt.cc.o.d
-fmodules-ts -fmodule-mapper=CMakeFiles/fmt.dir/src/fmt.cc.o.modmap -MD
-fdeps-format=p1689r5 -x c++ -o CMakeFiles/fmt.dir/src/fmt.cc.o -c
/mnt/d/dev/libs/tools/cpp/fmt/src/fmt.cc
In file included from /mnt/d/dev/libs/tools/cpp/fmt/src/fmt.cc:148:
/mnt/d/dev/libs/tools/cpp/fmt/src/os.cc:74:7: error: ‘using
{anonymous}::rwresult = ssize_t’ exposes TU-local entity ‘{anonymous}’
74 | using rwresult = ssize_t;
| ^~~~~~~~
/mnt/d/dev/libs/tools/cpp/fmt/src/os.cc:62:1: note: ‘{anonymous}’
declared with internal linkage
62 | namespace {
| ^~~~~~~~~
My shallow understanding of the standard
<https://timsong-cpp.github.io/cppwp/n4659/basic.link#8> and P1815
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1815r2> is
that it looks like gcc is correct to disallow this code (anonymous
namespace is exposed as TU-local because rwresult has linkage because
ssize_t is a fundamental type).
However, when working around this error (either by moving the `using`
statement within the functions bodies or by creating a macro for
`rwresult`
<https://github.com/fmtlib/fmt/commit/9381bba8d967428dd4829b2fcc0c32199ef41ed3#diff-261f435b8f5004993798511d1dc333e917901cbb2e83e73592d5bd2f3082c7bc>),
gcc is happy with `convert_rwcount`, which should also have internal
linkage and therefore expose the anonymous namespace as TU-local and
therefore report the same error.
Would anyone know what am I missing? If GCC is correct about
convert_rwcount then I would like to understand if there is anything we
can do to rwresult to make it happy.
Thanks in advance,
Thomas
PS: full steps to reproduce the error, with GCC 15.0.1 20250214
(installed in /opt/gcc-dev) and cmake 3.31.5:
git clone -b gcc-15-fixes-test https://github.com/tkhyn/fmt
mkdir fmt/build && cd fmt/build
export CXX=/opt/gcc-dev/bin/g++
export CC=/opt/gcc-dev/bin/gcc
cmake .. -DFMT_MODULE=ON
cmake --build . --target fmt
To make the error disappear, make these changes
<https://github.com/fmtlib/fmt/commit/9381bba8d967428dd4829b2fcc0c32199ef41ed3#diff-261f435b8f5004993798511d1dc333e917901cbb2e83e73592d5bd2f3082c7bc>
to os.cc.