Bug 121707 - Compiler spills std::string internals when used in consteval context
Summary: Compiler spills std::string internals when used in consteval context
Status: RESOLVED DUPLICATE of bug 97740
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2025-08-28 15:51 UTC by Peter Bindels
Modified: 2025-09-02 20:59 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Bindels 2025-08-28 15:51:50 UTC
When compiling the below source code


#include <string>

template <typename = void>
struct T {
    static constexpr std::string value{};
};

void f() {
    T<>::value;
}


the compiler fails on the line in f() with the following error referring to the members of the std::string being private:



<source>:5:34: error: 'std::__cxx11::basic_string<char>::<unnamed union> std::__cxx11::basic_string<char>::<anonymous>' is private within this context
    5 |     static constexpr std::string value{};
      |                                  ^~~~~
In file included from /cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/string:56,
                 from <source>:1:
/cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/bits/basic_string.h:220:7: note: declared private here
  220 |       union
      |       ^~~~~
<source>:5:34: error: 'char std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf [16]' is private within this context
    5 |     static constexpr std::string value{};
      |                                  ^~~~~
/cefs/b6/b615954805438726f22a60c9_converted_gcc-15.2.0/include/c++/15.2.0/bits/basic_string.h:222:26: note: declared private here
  222 |         _CharT           _M_local_buf[_S_local_capacity + 1];
      |                          ^~~~~~~~~~~~


The same code works fine in Clang. Checked with `-std=c++26`.


https://godbolt.org/z/844x68798
Comment 1 Drea Pinski 2025-08-28 16:08:21 UTC
Note this is most likely a dup of either PR 109576, bug 96716 or PR 97740 (or all 3 are dups of each other).
Comment 2 Patrick Palka 2025-09-02 20:59:12 UTC
yep, let's mark this one as a dup

*** This bug has been marked as a duplicate of bug 97740 ***