Title
explicit and eligible constructors
Status
open
Section
11.4.4 [special]
Submitter
Jason Merrill

Created on 2026-09-30.00:00:00 last changed yesterday

Messages

Date: 2026-09-30.21:35:38

Possible resolution:

Change in 11.4.4 [special] paragraph 6 as follows:

An eligible special member function is a special member function for which:
  • the function is not deleted,
  • the associated constraints (13.5 [temp.constr]), if any, are satisfied, and
  • no special member function of the same kind and at most as explict (9.2.3 [dcl.fct.spec]) whose associated constraints, if any, are satisfied is more constrained (13.5.5 [temp.constr.order]).,

where a function F1 is at most as explicit as a function F2 if

  • both are explicit or neither is or
  • F1 is not explicit and F2 is explicit.

Date: 2026-09-30.00:00:00

Consider:

  template <class T>
  struct X {
    X() = default;
    X(const X&) = default;
  private:
    explicit X(const X&) requires (T::value) = default;  // #1
  };

  struct S { static constexpr bool value = true; };

  int main() {
    const X<S> x;
    X<S> x2 = x;     // #2
  }

According to 11.4.4 [special] paragraph 6, the public copy constructor is not eligible, because #1 is more constrained. This causes it to be deleted (9.6.2 [dcl.fct.def.default] paragraph 5). Yet, the public copy constructor is selected by overload resolution when used at #2.

History
Date User Action Args
2026-09-30 19:11:00adminsetmessages: + msg8689
2026-09-30 00:00:00admincreate