Question Details

No question body available.

Tags

c++ language-lawyer copy-constructor requires-clause

Answers (1)

May 11, 2026 Score: 2 Rep: 280,997 Quality: Medium Completeness: 60%

ill-formed is a very strong word in the standard; it is used for very fundamental errors (as well as the ill-formed, no diagnostic requried bugs).

In effect, you are doing something roughly equivalent, in standard-wording, to:

A(decltype(auto) x) requires false {}

That placeholder type decltype(auto) makes the program ill-formed, even though the constructor doesn't exist.

The standard is probably overly strict here. But even if you have a requires false (or equivalent) you are still a declaration, and that declaration cannot be ill-formed, as the standard is written.

Modifying this is tricky as far as I can tell. Determining if a requires-clause could possibly return true (or is always false) for a given template instantiation is impossible in the general case. Here, of course, it is easy; but the standard has to decide what to do when it isn't possible, and asking compilers to do an impossible task is not really good way to write a standard.

A possible "fix" would be to defer this requirement to overload resolution time; if a constructor of that form is found at overload resolution time the constructor becomes ill-formed? But that sort of sucks, we'd want to check this before we use the class.

We could posit a pretend lookup of like X( std::declval() ), and state that if that lookup includes a constructor of the form X(X) in its possible overload set that constructor is ill-formed? I'm not sure if that is identical in the "simple" case, and sufficient in the "pathological" cases, but it seems possible.

You cannot pass template parameters to constructors (at least at this time), and the case we are trying to block is having to copy-construct in order to copy-construct (!), so the detection of that case might be sufficient for what the language is trying to block here.