[Bug c++/85032] New: Wrong non-constant condition for static assertion

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 22 08:34:00 GMT 2018


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

            Bug ID: 85032
           Summary: Wrong non-constant condition for static assertion
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

We should accept this one

struct A
{
  constexpr operator bool () { return true; }
  int i;
};

A a;

template <class T> void f()
{
  constexpr bool b = a;
  static_assert (a);
}

int main()
{
  f<int>();
}

instead, we reject it with 
constexpr-if17.C: In function ‘void f()’:
constexpr-if17.C:12:18: error: non-constant condition for static assertion
   static_assert (a);
                  ^
constexpr-if17.C:12:18: error: the value of ‘a’ is not usable in a constant
expression
constexpr-if17.C:7:3: note: ‘a’ was not declared ‘constexpr’
 A a;
   ^


More information about the Gcc-bugs mailing list