c++ - Should Taking the Address of a Templatized Function Trigger its Compilation? -
i got official answer this question decltype
should not trigger function compilation. in fact decltype
on function declared not defined legal.
next question, should taking address of function trigger compilation of function? take this example:
template <typename t> void foo(t&& x) { x.func(); } int main() { auto bar = &foo<int>; }
all compilers i've tested fail error like:
request member
func
inx
, of non-class typeint
but if define foo
, don't declare it, code compiles fine. can provide me official source on whether taking address of function should require it's compilation?
3.2/2:
an expression potentially evaluated unless unevaluated operand (clause 5) or subexpression thereof. ... non-overloaded function name appears potentially-evaluated expression or member of set of candidate functions, if selected overload resolution when referred potentially-evaluated expression, odr-used, unless pure virtual function , name not explicitly qualified.
then 3.2/3:
every program shall contain 1 definition of every non-inline function or variable odr-used in program; no diagnostic required. definition can appear explicitly in program, can found in standard or user-defined library, or (when appropriate) implicitly defined (see 12.1, 12.4 , 12.8). inline function shall defined in every translation unit in odr-used.
the function name not unevaluated operand (for example sizeof
, decltype
), , appears in expression, it's potentially evaluated. second 1 requires 1 non-inline definition, or identical inline definitions in each translation unit.
Comments
Post a Comment