On Wednesday, October 25, 2017 at 5:39:53 AM UTC-7, Corentin wrote:
I think this is initially attractive... but you can't say just "don't do name lookup." As Myriachan points out, something like name-lookup is required in order to figure out whether a line of tokens has "valid syntax". For example:
foo * bar ;
could be ill-formed, or a variable definition, or a multiplication expression-statement, depending on the "part of speech" of foo and bar respectively, which can be determined by name-lookup or else by the compiler picking a "plausible default" (which is what it does in uninstantiated templates). The "plausible default" here is that both names are assumed to be values/variables, and if you want them to be typenames you must put the keyword "typename" in front of the qualified name.
The reason we don't have to litter our templates with "typename" keywords is because the compiler generally does full name lookup on every name that is not "dependent" on any template parameter. So for example
template<class T>
void foo() {
using A = typename bar<T>::baz; // OK only with "typename"
using B = bar<int>::baz; // OK without "typename"
}
because bar<T>::baz is "dependent" on template parameter T, whereas bar<int>::baz is not "dependent" on anything.
But in the case of `if constexpr (false)`, what would constitute a "dependent" construct? There are no parameters to `if constexpr (false)` for anything to "depend" on. And we don't want to make every construct "dependent" because then we'd have to write "typename" and "template" keywords all over the place just to get anything to compile at all, which would be awful — much worse than the status quo.
So what would you want the new behavior of `if constexpr (false)` to be, then? Can you draw any parallels to anything in the existing C++ language?
HTH,
Arthur