I got an official answer to this question that decltype
should not trigger function compilation. In fact decltype
on a function that is declared but not defined is legal.
Next question, should taking the address of a function trigger the compilation of a function? Take this example:
template <typename T>
void foo(T&& x) { x.func(); }
int main()
{
auto bar = &foo<int>;
}
All the compilers I've tested fail with an error like:
Request for member
func
inx
, which is of non-class typeint
But if I just define foo
and don't declare it, the code compiles fine. Can someone provide me with an official source on whether taking the address of a function should require it's compilation?
3.2/2:
Then 3.2/3:
The function name is definitely not an unevaluated operand (for example to
sizeof
,decltype
), AND it appears in an expression, so it's potentially evaluated. Then the second one requires exactly one non-inline definition, or identical inline definitions in each translation unit.