Conditional operator's return type and two-phase lookup

后端 未结 3 1333
悲&欢浪女
悲&欢浪女 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:23

    I think gcc (and visual studio, by the way) are right on this one.

    n4582, §14.6.2.2

    Except as described below, an expression is type-dependent if any subexpression is type-dependent.

    In T{} ? d : d, there are 3 sub expressions:

    • T{}, obviously type dependent
    • d (2 times), not type dependent

    Since there is a type dependent sub expression and the ternary operator does not figure in the list of exceptions in §14.6.2.2, it is considered type dependent.

提交回复
热议问题