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

            Bug ID: 91483
           Summary: Poor diagnostic on trying to take constexpr reference
                    to non-static object
           Product: gcc
           Version: 9.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider:

struct X {
    int const& var;
};

void foo() {
    constexpr int i = 42;
    constexpr X x{i};
}

This is ill-formed because i doesn't have static storage duration. But the
error gcc provides is:

<source>: In function 'void foo()':
<source>:7:20: error: 'const X{i}' is not a constant expression
    7 |     constexpr X x{i};
      |                    ^

It would be a lot nicer if the diagnostic here explained the reason that this
isn't a constant expression.

Reply via email to