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

            Bug ID: 77446
           Summary: Suspicious "non-constant condition for static
                    assertion" error
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: TonyELewis at hotmail dot com
  Target Milestone: ---

I'm compiling the following under C++14 mode on HEAD 7.0.0 201608 of
http://melpon.org/wandbox/



struct inner {
  int  field_a = 0;
  bool field_b = false;

  explicit constexpr inner(const int &arg_field_a) noexcept : field_a{
arg_field_a } {}
};

struct outer {
  inner the_inner = inner{ 0 };

  constexpr outer() noexcept = default;
  constexpr int set_inner(const inner &arg_inner) {
    the_inner = arg_inner;
    return 0;
  }
};

constexpr inner another_inner{ 1 };
static_assert( outer{}.set_inner( another_inner ) == 0,  "" );

int main() {}



...and seeing this error:



prog.cc:19:1: error: non-constant condition for static assertion
 static_assert( outer{}.set_inner( another_inner ) == 0,  "" );
 ^~~~~~~~~~~~~



I suspect this is a compiler error, particularly because;
 * Commenting out the field_b line makes it work.
 * Clang compiles this without complaint.
 * The error message appears to be inconsistent, sometimes gaining the
following messages after the messages above...


prog.cc:19:33:   in constexpr expansion of
'outer{inner(0)}.outer::set_inner(another_inner)'
prog.cc:19:1: error: accessing value of '<anonymous>.outer::the_inner' through
a 'char [5]' glvalue in a constant expression



Many apologies if this is a false positive.

Many thanks for all your hard work on this wonderful compiler.

Reply via email to