https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125398
Bug ID: 125398
Summary: [reflection] Use of std::meta::reflect_constant_array
across module boundary results in error
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: friedkeenan at protonmail dot com
Target Milestone: ---
If one has a module `mod` in a `mod.cpp` file with the following code:
```
module;
#include <meta>
export module mod;
export consteval auto mod_func(auto &&r) -> std::meta::info {
return std::meta::reflect_constant_array(r);
}
```
And a `main.cpp` file which imports and uses that module:
```
import mod;
int main() {
constexpr auto s = mod_func("string");
}
```
And with the following `CMakeLists.txt` to connect them together:
```
cmake_minimum_required(VERSION 4.1)
project(example)
add_library(mod)
target_compile_features(mod PUBLIC cxx_std_26)
target_compile_options(mod PUBLIC -freflection)
target_sources(mod PUBLIC
FILE_SET CXX_MODULES
FILES
mod.cpp
)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE mod)
```
Then this will result in the following error when building:
```
main.cpp:4:32: in 'constexpr' expansion of 'mod_func@mod<const char
(&)[7]>("string")'
4 | constexpr auto s = mod_func("string");
| ~~~~~~~~^~~~~~~~~~
mod.cpp:8:45: error: 'std::ranges' is not a namespace
8 | return std::meta::reflect_constant_array(r);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
main.cpp:4:32: in 'constexpr' expansion of 'mod_func@mod<const char
(&)[7]>("string")'
4 | constexpr auto s = mod_func("string");
| ~~~~~~~~^~~~~~~~~~
mod.cpp:8:45: error: 'std::ranges' is not a namespace
8 | return std::meta::reflect_constant_array(r);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
main.cpp:4:32: in 'constexpr' expansion of 'mod_func@mod<const char
(&)[7]>("string")'
4 | constexpr auto s = mod_func("string");
| ~~~~~~~~^~~~~~~~~~
mod.cpp:8:45: error: 'std::ranges' is not a namespace
8 | return std::meta::reflect_constant_array(r);
|
```
This error also occurs when using `std::meta::rwflect_constant_string`, and
`std::define_static_string`, the latter of which is how I came upon the error.
Here is a Godbolt link for the erroring project:
https://godbolt.org/z/b6o9Kd3hv
If one adds `#include <ranges>` to `main.cpp`, then with GCC trunk the error
can be avoided. This doesn't seem to work with my local GCC 16.1.1, however,
which seems to get caught on some separate bug that's been fixed in trunk.