c++ - Potential evaluation of inline function bodies and instatiation of template members -
c++ - Potential evaluation of inline function bodies and instatiation of template members -
when expressions contained within function marked inline considered 'potentially evaluated'?
a.cpp
template <typename t> const t& foo(const t& arg) { homecoming arg; } inline void dead() { int x(21); x = foo(x); }
b.cpp
#include <iostream> template <typename t> const t& foo(const t&); int main(int argc, char *argv[]) { std::cout << foo(12) << std::endl; }
if expressions considered 'potentially evaluated' inline function defined, template should instantiated, , expect $(ccc) -c a.cpp; $(ccc) -c b.cpp; $(ccc) a.o b.o -o bin
link successfully. if instead expressions within function declared inline become 'potentially evaluated' when such function becomes odr-used, expect $(ccc) -c a.cpp; $(ccc) -c b.cpp; $(ccc) a.o b.o -o bin
fail during link step.
thus far have tested xl c++ 12 (which links successfully), , various versions of gcc + clang 3.5 (all of fail link).
which behaviour correct? missing 3rd alternative here?
§14 [temp]/p6:
a function template, fellow member function of class template, variable template, or static info fellow member of class template shall defined in every translation unit in implicitly instantiated (14.7.1) unless corresponding specialization explicitly instantiated (14.7.2) in translation unit; no diagnostic required.
your code ill-formed no diagnostic required. both compilers behaving correctly.
c++ c++11 language-lawyer inline-functions odr
Comments
Post a Comment