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

            Bug ID: 92003
           Summary: constexpr-ness of char const* doesn't propagate
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

For some reasons the compiler seems to differ between a constexpr char const*
which is directly initialized by a string literal and one which actually points
to a constexpr char array.

The last expression in the following code-snippet fails to compile on the
current trunk:

constexpr char const* get_c_str() { return "abc"; }
constexpr bool use_get_c_str_in_constexpr_context{get_c_str()}; // works

template <char... Cs>
struct string {
  static constexpr char const* c_str() { return &c[0]; }

 private:
  static constexpr char c[]{Cs..., '\0'};
};

constexpr char const* cstr{string<'a', 'b', 'c'>::c_str()};
constexpr bool use_cstr_in_constexpr_context{cstr}; // doesn't work


https://godbolt.org/z/k3TBUC

Reply via email to