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

--- Comment #3 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Actually wait.  I think this is invalid and clang is incorrect in not
> rejecting it.  Because you have a call to a non constexpr in a constexpr
> function; does not matter if it is after a return or not.

My program is valid. Just having a call expression with a non-constexpr
function inside the body of a constexpr function is not in it self a reason for
the program to be ill-formed.

The c++ standard is quite permissive about what a function body of a constexpr
function can contain, see [dcl.constexpr]p3
(http://eel.is/c++draft/dcl.constexpr#3).

The program would however be ill-formed with no diagnostics required, if the
constexpr function could never be called without calling the non-constexpr
function. For details, see [dcl.constexpr]p5
(http://eel.is/c++draft/dcl.constexpr#5).

Also the program wold be ill-formed, if the constexpr function needs to be
called when evaluating an expression that needs to be a constant expression,
and that call would result in a call to the non-constexpr function. For
details, see [expr.const]p2 (http://eel.is/c++draft/expr.const#2) (item 2 in
the list).


I choose the return type void to avoid having to return a value in f. The test
case works with int as return type also.

  void g() {}
  constexpr int f() { return 0; g(); }
  int main() {}

Anyways GCC supports the return type void for constexpr functions. Also relaxed
requirements on constexpr functions have been implemented since version 5 of
GCC according to this:

https://gcc.gnu.org/projects/cxx1y.html

Reply via email to