Function call of non-constexpr function in constexpr function.

46 views
Skip to first unread message

Anders Granlund

unread,
Jul 24, 2015, 10:54:53 PM7/24/15
to ISO C++ Standard - Discussion
The following program compiles without errors on clang, but gives an error with gcc:

void g() { }

constexpr void f() {
    return;
    g();
}

int main() {}

Is this program Ill-formed, and if so is diagnostics required?

David Krauss

unread,
Jul 24, 2015, 11:00:06 PM7/24/15
to std-dis...@isocpp.org
It’s fine. GCC hasn’t yet fully relaxed its constexpr.

StackOverflow is a good resource for basic understanding of the standard, by the way.

Anders Granlund

unread,
Jul 24, 2015, 11:11:27 PM7/24/15
to std-dis...@isocpp.org
Doesn't this table suggests that relaxing requirements on constexpr functions have been fully implemented in gcc? https://gcc.gnu.org/projects/cxx1y.html

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.

Anders Granlund

unread,
Jul 26, 2015, 8:18:48 PM7/26/15
to std-dis...@isocpp.org
Anyways the program seems to be ill-formed with no diagnostics required [dcl.constexpr]/5 (http://eel.is/c++draft/dcl.constexpr#5), so it's not a problem that the compilers disagree.

David Krauss

unread,
Jul 26, 2015, 10:02:33 PM7/26/15
to std-dis...@isocpp.org

On 2015–07–27, at 8:18 AM, Anders Granlund <anders.g...@gmail.com> wrote:

Anyways the program seems to be ill-formed with no diagnostics required [dcl.constexpr]/5 (http://eel.is/c++draft/dcl.constexpr#5), so it's not a problem that the compilers disagree.

The offending expression is never evaluated. The program is well formed. GCC is wrong. Clang is required to accept and execute it.

Anders Granlund

unread,
Jul 27, 2015, 9:26:40 AM7/27/15
to std-dis...@isocpp.org
But it is not an unevaluated operand, doesn't that make a difference?

David Krauss

unread,
Jul 27, 2015, 9:34:53 AM7/27/15
to std-dis...@isocpp.org

> On 2015–07–27, at 9:26 PM, Anders Granlund <anders.g...@gmail.com> wrote:
>
> But it is not an unevaluated operand, doesn't that make a difference?

The relevant condition is where [expr.const] §5.20/2 mentions “the abstract machine would evaluate one of the following expressions.” Constexpr functions are forbidden from having certain kinds of declarations and statements, but not subexpressions. Anyway, the rules about what’s allowed in a constexpr function body aren’t NDR.

Anders Granlund

unread,
Jul 27, 2015, 10:08:45 AM7/27/15
to std-dis...@isocpp.org
Ok, I'll report the bug to GCC then.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.

Anders Granlund

unread,
Jul 27, 2015, 10:20:29 AM7/27/15
to std-dis...@isocpp.org
If we changed the program to:

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

Then it would be ill-formed by  [dcl.constexpr]/5 (http://eel.is/c++draft/dcl.constexpr#5) with NDR?

And if we changed it to:

void g() { }
constexpr void f(bool b) { if (b) g(); return; }
int main() {}

Then it would be well-formed.

David Krauss

unread,
Jul 27, 2015, 10:40:11 AM7/27/15
to std-dis...@isocpp.org
On 2015–07–27, at 10:20 PM, Anders Granlund <anders.g...@gmail.com> wrote:

If we changed the program to:

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

Then it would be ill-formed by  [dcl.constexpr]/5 (http://eel.is/c++draft/dcl.constexpr#5) with NDR?

Right.

And if we changed it to:

void g() { }
constexpr void f(bool b) { if (b) g(); return; }
int main() {}

Then it would be well-formed.


Yep.

Anders Granlund

unread,
Jul 27, 2015, 10:44:53 AM7/27/15
to std-dis...@isocpp.org
Ok, then I understand what you mean.

Reply all
Reply to author
Forward
0 new messages