<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58754>58754</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            c++20/libstdc++: `char_traits.h:213:13: note: subexpression not valid in a constant expression`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          timblechmann
      </td>
    </tr>
</table>

<pre>
    using this constexpr boost static_string (requires static_string develop) does not compile with clang against libstdc++ (g++ compiles against libstdc++ also clang++ compiles against libc++).

```
#include <boost/static_string.hpp>
using str = boost::static_strings::static_string<38>;
constexpr str a{ "mystr" };
```

```
c.cpp:5:15: error: constexpr variable 'a' must be initialized by a constant expression
constexpr str a{ "mystr" };
              ^~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/char_traits.h:213:13: note: subexpression not valid in a constant expression
   if (__s1 == __s2)
            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/char_traits.h:417:11: note: in call to 'move(&a.static_string_base::data_[0], &"mystr"[0], 5)'
   return __gnu_cxx::char_traits<char_type>::move(__s1, __s2, __n);
          ^
/home/tim/NIBuild/3rdparty/boost-v1.78.0-R8/boost/static_string/static_string.hpp:6000:3: note: in call to 'move(&a.static_string_base::data_[0], &"mystr"[0], 5)'
  traits_type::move(data(), s, size());
  ^
/home/tim/NIBuild/3rdparty/boost-v1.78.0-R8/boost/static_string/static_string.hpp:1413:12: note: in call to '&a->assign(&"mystr"[0], 5)'
    return assign(s, traits_type::length(s));
           ^
/home/tim/NIBuild/3rdparty/boost-v1.78.0-R8/boost/static_string/static_string.hpp:961:5: note: in call to '&a->assign(&"mystr"[0])'
    assign(s);
    ^
c.cpp:5:15: note: in call to 'basic_static_string(&"mystr"[0])'
constexpr str a{ "mystr" };
              ^
1 error generated.
```

the offending code in libstdc++ is this one:
```
          if (__s1 == __s2) // unlikely, but saves a lot of work
            return __s1;
```
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/char_traits.h#L216-L217

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVtuO4ygQ_RrnBcWycXx78EP39ERaabUP-wMRtonNDoYs4Exnv36rjJN20unMrEY7E5ECcymqDgeqat2eqtEK1RHXC0sarazjrwdDaq2tI9YxJ5qddQanBLQw_O9RGG5vRlp-5FIfAlqSVsOo0g50DQchOfkqXE8ayWAa65iADYgUtXVtE9BnKKi2m5vzGvvBTCat9qoezJ8ngy1hEL0E0dMss2gu_pMmQjVybDkJkk-TtwHdXnkV9odDkHz28z1IMADTXzw6QfIE5WqJvdMH6pMC9STPXtUbyKiOBTlCQIcTfEFNgvzlMvXW6HudTdignU8p_GMUhBujDTbedjoyI1gNpxHQnMGfDCOgVXMilHCCSfEPb0l9IsyvYcoRXMetFVr9Z7PJ1S9IPwf5t8p8KNvRgrZtLRTIMAQBJwqya-BYt69Ftss2aynU-Lru1AhdMT1PvBHz6ULrQgg_uRbOYm_PzM4ZBl9hD2DROEEAUSB9OdZ2rN9QmEh9BKhaAO0RUOCy2COrdzsbI12QMdCGzcv3-CA6v9z5TZyj8_HSeXCyYVISp5E0gz6CuiKgGQuv6L2rmeWe9i1zbBekz1GQvgT0EyzLFgxZDKSIBM0vYBjuRqMAI3Br17y-enULI-EO-a_TgU9XCcdnkxBlVOoRxlqh-vdcXCLd6wHRcWIA-cdvz6OQLbQS0x6YcSdECq_4-hiHeRFG6z-Lc9ftK3H_1XjKoiiCKvk1iHrUZrgWWKG-ac8SF9lJwNU_dy1R-6loxRt_--jHcCFOazh7BjetUx6472PXmV6XlZPf7yCSXHWu98PlfQb9XFDKLJ6f9R-E5BqNJQzXTl68ex9S7hsARJ2MvvLl21b8UCSZumMf40jHFTfM8TZ8EC9dz4ne77lqMYQ3usWod5NZQO4zJUB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