Are explicit conversion operators allowed in braced initializer lists?

后端 未结 3 482
逝去的感伤
逝去的感伤 2021-01-11 09:28

The following code compiles with GCC 4.9.2 but not with Clang 3.5.0:

#include 

class Foo
{
public:
  explicit operator std::string() const;
};         


        
3条回答
  •  独厮守ぢ
    2021-01-11 09:47

    This seems to be a Clang bug. [over.match.list]/1:

    When objects of non-aggregate class type T are list-initialized (8.5.4), overload resolution selects the constructor in two phases:

    • [..]
    • If no viable initializer-list constructor is found, overload resolution is performed again, where the candidate functions are all the constructors of the class T and the argument list consists of the elements of the initializer list.

    Since the second line compiles fine, there is an inconsistency: They should be equivalent when it comes to overload resolution.

提交回复
热议问题