Reputation: 1388
The newly published draft mentions in [expr.prim.req]/6:
If the substitution of template arguments into a requirement would always result in a substitution failure, the program is ill-formed; no diagnostic required. [ Example:
template<typename T> concept C = requires { new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required };
— end example ]
But why can't we guarantee the diagnostic to always fail, rather than skip the diagnostic?
Upvotes: 2
Views: 165
Reputation: 473397
Requirement expressions can do pretty much anything. They can provoke further template substitutions, cascading outwardly through an arbitrary amount of code. And recall that template substitutions constitute a Turning complete language.
So you're asking the compiler to, given a Turing complete program, prove whether there is some input which causes that program to be well-formed. This is just a restatement of the Halting Problem. Just like the Halting Problem, there are simple cases where it's obvious the program halts/doesn't halt. But when you're dealing with a Turing-complete language, it can get arbitrarily complex.
The standard isn't going to force compilers to solve the Halting Problem.
Upvotes: 6