Conditional operator's return type and two-phase lookup

后端 未结 3 1335
悲&欢浪女
悲&欢浪女 2021-02-06 21:42

Consider the following snippet:

struct Base { };
struct Derived : Base { };

void f(Base &) { std::cout << \"f(Base&)\\n\"; }

template 

        
3条回答
  •  忘了有多久
    2021-02-06 22:35

    According to c++ draft (n4582) §14.7.1.5:

    Unless a function template specialization has been explicitly instantiated or explicitly specialized, the function template specialization is implicitly instantiated when the specialization is referenced in a context that requires a function definition to exist. Unless a call is to a function template explicit specialization or to a member function of an explicitly specialized class template, a default argument for a function template or a member function of a class template is implicitly instantiated when the function is called in a context that requires the value of the default argument.

    I would say gcc is more correct about this.

    If you for example create an specialized version of void g() you get both compiler doing the same.

提交回复
热议问题