https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118863
Bug ID: 118863
Summary: Cannot #include <string> in global module fragment
with -fsanitize=undefined
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: davidfromonline at gmail dot com
Target Milestone: ---
The following code
```c++
module;
#include <string>
export module m;
```
when compiled with `-std=c++23 -fmodules-ts -fsanitize=undefined` causes gcc to
fail with
```console
<source>:5:8: internal compiler error: in tree_node, at cp/module.cc:9767
5 | export module m;
| ^~~~~~
0x2914845 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
???:0
0x292b916 internal_error(char const*, ...)
???:0
0xacf882 fancy_abort(char const*, int, char const*)
???:0
0xc572ad depset::hash::find_dependencies(module_state*)
???:0
0xc57c4a module_state::write_begin(elf_out*, cpp_reader*, module_state_config&,
unsigned int&)
???:0
0xc59454 finish_module_processing(cpp_reader*)
???:0
0xbdb7c3 c_parse_final_cleanups()
???:0
0xe51ad8 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
https://godbolt.org/z/vrzh3WvTc
This can be reduced to
```c++
module;
constexpr bool is_constant_evaluated() noexcept {
if consteval {
return true;
} else {
return false;
}
}
template<typename>
struct s {
s() {
is_constant_evaluated();
}
};
extern template struct s<char>;
s<char> a;
export module m;
```
Which fails with
```console
<source>:3:1: warning: global module fragment contents must be from
preprocessor inclusion [-Wglobal-module]
3 | constexpr bool is_constant_evaluated() noexcept {
| ^~~~~~~~~
<source>:22:8: internal compiler error: in tree_node, at cp/module.cc:9767
22 | export module m;
| ^~~~~~
0x2914845 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
???:0
0x292b916 internal_error(char const*, ...)
???:0
0xacf882 fancy_abort(char const*, int, char const*)
???:0
0xc572ad depset::hash::find_dependencies(module_state*)
???:0
0xc57c4a module_state::write_begin(elf_out*, cpp_reader*, module_state_config&,
unsigned int&)
???:0
0xc59454 finish_module_processing(cpp_reader*)
???:0
0xbdb7c3 c_parse_final_cleanups()
???:0
0xe51ad8 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
https://godbolt.org/z/G1b15b858