http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57941

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-07-20
                 CC|                            |manu at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.8.0, 4.9.0

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Confirmed. It also fails on trunk.

Clang++:

test.cc:10:16: error: static_assert expression is not an integral constant
expression
static_assert (a <int> (), "foo");
               ^~~~~~~~~~
test.cc:5:31: note: non-constexpr function 'c' cannot be used in a constant
expression
  constexpr int b () { return c (); }
                              ^
test.cc:4:22: note: in call to ')'
  constexpr a (): i (b ()) { }
                     ^
test.cc:10:16: note: in call to 'a()'
static_assert (a <int> (), "foo");
               ^
test.cc:6:7: note: declared here
  int c () const { throw 42; }
      ^
1 error generated.

which is not perfect but it is clearly better.

The code that handles this is at explain_invalid_constexpr_fn at
/home/manuel/test1/src/gcc/cp/semantics.c:6461

  save_loc = input_location;
  input_location = DECL_SOURCE_LOCATION (fun);
  inform (0, "%q+D is not usable as a constexpr function because:", fun);
  /* First check the declaration.  */
  if (is_valid_constexpr_fn (fun, true))
    {
      /* Then if it's OK, the body.  */
      if (DECL_DEFAULTED_FN (fun))
        explain_implicit_non_constexpr (fun);
      else
        {
          body = massage_constexpr_body (fun, DECL_SAVED_TREE (fun));
          require_potential_rvalue_constant_expression (body);
          if (DECL_CONSTRUCTOR_P (fun))
            cx_check_missing_mem_inits (fun, body, true);
        }
    }
  input_location = save_loc;

I don't understand the point of the first "if", since if it is ever not taken
it would be a bug.

However, in this case, interestingly, the "if" is taken, but then nothing else
prints any explanation. I didn't investigate in detail why.

Also, playing tricks with input_location is not so nice.

Reply via email to