https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124404
Bug ID: 124404
Summary: __builtin_constexpr_diag() doesn't work with
std::string
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ivan.lazaric.gcc at gmail dot com
Target Milestone: ---
```
#include <string>
consteval {
std::string msg = "world";
__builtin_constexpr_diag(2, "", msg);
}
```
Compiled with flags: "-std=c++26"
Compiler log:
```
<source>:5:29: error: request for member 'size' in '<anonymous>', which is of
pointer type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} (maybe
you meant to use '->' ?)
5 | __builtin_constexpr_diag(2, "", msg);
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
<source>:5:29: error: constexpr string must be a string literal or object with
'size' and 'data' members
```
It says `std::string&` is a pointer type, which is wrong.
I don't know if this is not meant to work, but the diagnosis is confusing.
The same code works as expected (in that it is ill-formed with "world"
diagnosis)
if `std::string_view` is used instead.
Godbolt of example: https://godbolt.org/z/T3bbqGWfn