static_string icon indicating copy to clipboard operation
static_string copied to clipboard

`constexpr boost::static_strings::basic_static_string s( "name" );` fails

Open pdimov opened this issue 1 year ago • 4 comments

constexpr boost::static_strings::basic_static_string s( "name" ); fails to compile (under C++20): https://godbolt.org/z/fvPs3rxa7

Background: in order to write functions that take strings as template arguments, as in function<"string">(), one needs to declare the template parameter a static string, because neither char const* nor std::string_view work.

To avoid needless reinvention of static strings, ours should (probably) be useful in this role. But it isn't, for at least the reason above.

pdimov avatar Jan 01 '24 19:01 pdimov

@pdimov This is because of a shortsighted design choice I made to optimize zero size strings, accomplished via a virtual base class. Removing this and making the non-static data members public would allow for it to be used as a NTTP.

sdkrystian avatar Jan 02 '24 02:01 sdkrystian

I think this specific problem isn't caused by the class not being structural, though. The error comes from std::char_traits.

pdimov avatar Jan 02 '24 15:01 pdimov

Looks like an issue with libstdc++.

pdimov avatar Jan 02 '24 15:01 pdimov

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

pdimov avatar Jan 02 '24 15:01 pdimov