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

            Bug ID: 87497
           Summary: constexprs involving non-literal const variables are
                    incorrectly accepted
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rsandifo at gcc dot gnu.org
  Target Milestone: ---

G++ accepts:

struct s { volatile int x; int y; };
constexpr int foo (const s &s1) { return s1.y; }
void g () { const s local_s = { 1, 2 }; constexpr int a = foo (local_s); }

even though "local_s" is only const, not constexpr (and couldn't be constexpr
due to having a non-literal type).

From Jonathan on IRC:

  I think for foo(local_s) to be a constant expression, local_s needs to be a
constexpr variable, or a non-volatile const-qualified integer, or a reference
  http://eel.is/c++draft/expr.const#8.7

Reply via email to