Consider this example code:
template
char register_(){
return D::get_dummy(); // static function
}
template
struct Foo{
We can use a simple trick based on a declaration that must be instantiated with the class:
template<…>
struct Auto {
static Foo foo;
static_assert(&foo);
};
template<…> Foo Auto::foo=…;
Note that some compilers warn about the comparison to null; that can be avoided with &foo==&foo, (bool)&foo, or ((void)&foo,true) if needed.
Note also that GCC 9.0–9.2 don’t count this as an odr-use.