https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110158

--- Comment #6 from danakj at orodu dot net ---
In case it is of help, here's an even smaller repro that clang reports the
error in libstdc++. For whatever reason gcc does not notice the libstdc++ bug
here.

https://gcc.godbolt.org/z/Phndafeoe

```
#include <string>

struct S {
    constexpr ~S() {}

    std::string s;
};

constexpr std::string foo(const S& s) { return s.s; }

static_assert(foo(S("hi")) == "hi");  // Fails.
static_assert(foo(S("a longer string works")) == "a longer string works");

int main() {}
```

The error:
```
<source>:11:15: error: static assertion expression is not an integral constant
expression
static_assert(foo(S("hi")) == "hi");
              ^~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/basic_string.h:356:10:
note: assignment to member '_M_local_buf' of union with no active member is not
allowed in a constant expression
            __c = _CharT();
                ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/basic_string.tcc:229:4:
note: in call to '&S(("hi")).s->_M_use_local_data()'
          _M_use_local_data();
          ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/basic_string.h:642:2:
note: in call to '&S(("hi")).s->_M_construct(&"hi"[0], &"hi"[2], {{}})'
        _M_construct(__s, __end, forward_iterator_tag());
        ^
<source>:11:21: note: in call to 'basic_string(&"hi"[0],
std::allocator<char>())'
static_assert(foo(S("hi")) == "hi");
                    ^
1 error generated.
```

Reply via email to