I was reading cppreference page for If statements, as well as C++17 standard (draft) and I also found out a (non exhaustive) pre-existing question on stackoverflow.
What I understand is that, within a template, a discarded sub-statement of an if constexpr is not instantiated, thereby not checked (unless the condition remains value-dependent, but let me suppose we are not in such a case).
Now, from both the C++17 standard (in §17.7, clause 8) and the current draft standard (in §13.8.1, clause 6) I read:
§13.8.1, clause 6 : The program is ill-formed, no diagnostic required, if
§13.8.1, clause (6.1): no valid specialization ... can be generated for a template or a substatement of a constexpr if statement (9.4.1) within a template and the template is not instantiated, or
...
§13.8.1: [Note 5: If a template is instantiated, errors will be diagnosed according to the other rules in this document.
Exactly when these errors are diagnosed is a quality of implementation issue. — end note ]
What the note seems reading to me is that "and the template is not instantiated" is added just because, in case of instantiations, there will be compiling errors as stated everywhere else in the standard.
Does all that mean that it is possible to have a sub-statement of an if constexpr containing code that cannot compile regardless of the template parameter ?
For example, with:
template<typename T>
void f(){
if constexpr(true){
} else{
char *p;
float f;
p = f;
}
}
(1) What should a compiler do in this case ?
(2) Will the behaviour be different with or without instantiations ?
(3) Why on godbolt I see compile error using clang but not with gcc ?
(4) Last, but not least, I see that cppreference refers CWG2518 with a proposal to allow having static_assert(false, ...) in the discarded sub-statement of an if constexpr -> check in particular the final part for "P2593R1 (static_assert(false))".
Reading the proposal generated several doubts about what should be the correct answer to previous questions. For example, if the answers to (1)/(2) are 'never error', then why we would need a specific proposal to allow static_assert(false) ?
On the other hand, if the answers to (1)/(2) are 'always error', then I am confused why the proposal does not contain special rules even for the case of template instantiations instead of only in the clause (6.1) that reads "and the template is not instantiated".