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

            Bug ID: 83692
           Summary: Rejects valid constexpr with unrelated code fixing
                    problem
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

The following program fails to compile

struct integer {
        constexpr int value() const {
                return m_value;
        }
        int m_value;
};

struct outer {
        integer m_x{0};
        constexpr outer() {
                if (m_x.value() != 0) throw 0;
                m_x.m_value = integer{1}.value();
                if (m_x.value() != 1) throw 0;
        }
};

constexpr outer o{};


Giving the error message:

17 : <source>:17:19:   in 'constexpr' expansion of 'outer()'
13 : <source>:13:37: error: expression '<throw-expression>' is not a constant
expression
         if (m_x.value() != 1) throw 0;
                                     ^
Compiler returned: 1



Seemingly insignificant changes in the code lead to the error disappearing: for
instance, removing the first if statement (which is not rejected as invalid)
causes the second if statement to be accepted.

Reply via email to