我觉得不看规范去猜也讨论不出什么结果,既然gcc和clang都认就大概能说明这个行为
是标准定义了的,翻到规范的8.5.1看看语法定义:
initializer:
brace-or-equal-initializer
( expression-list )
brace-or-equal-initializer:
= initializer-clause
braced-init-list
initializer-clause:
assignment-expression
braced-init-list
initializer-list:
initializer-clause ...opt
initializer-list , initializer-clause ...opt
braced-init-list:
{ initializer-list ,opt }
{}
可以看到{}内的东西最后就是initializer-list,opt
语义定义在202页,if otherwise包围的地方这么说的:
If the destination type is a (possibly cv-qualified) class type:
If...
Otherwise ,user-defined conversion sequences that can convert from the
source type to the destination type or (when a conversion function is used)
to a derived class thereof are enumerated as described in 13.3.1.4, and the
best one is chosen through overload resolution ,The function selected is
called with the initializer expression as its argument; if the function is a
constructor, the call initializes a temporary of the cv-unqualified version
of the destination type. The temporary is a prvalue
这样解释了为什么s2调用了和s1一样的constructor