Title
Recursion in constexpr template default constructor
Status
nad
Section
9.2.6 [dcl.constexpr]
Submitter
Daveed Vandevoorde

Created on 2013-03-11.00:00:00 last changed 132 months ago

Messages

Date: 2013-04-15.00:00:00

Rationale (April, 2013):

In the cited example, the constructor is constexpr; it simply cannot be used in a constant expression. The error would be detected at the time of such a use.

Date: 2022-11-20.07:54:16

Consider the following example:

  struct A {
    template <class T> constexpr void* f(T) { return nullptr; }
    A* ap = (A*)f(A());
    template <class ...T> constexpr A() {}
  };

A default constructor template instance would recurse infinitely via the member initializer for A::ap. However, since it's a template, by 9.2.6 [dcl.constexpr] paragraph 6, that would just mean that the instance shouldn't be treated as constexpr.

Is an implementation really expected to handle that? In effect, we have to try to evaluate the expression and if that fails, nullify the constexpr-ness of the A::A<>() instance, and re-examine the initializer with the new understanding of that instance?

History
Date User Action Args
2013-05-03 00:00:00adminsetmessages: + msg4438
2013-05-03 00:00:00adminsetstatus: open -> nad
2013-03-11 00:00:00admincreate