Can the constructor explainer supposedly be ignored due to the initialization form?

Consider this simple type:

struct A { A(int, int, int) {} A(std::vector<int>) {} }; /// A a({1,2,3}); 

The above snippet is a poorly formed program, since overload resolution fails because {1, 2, 3} can be used to initialize temporary A , so the c'tor copy is also viable to initialize A

Initially it was assumed that to solve the problem, you can use the marking of the first c'tor as explicit A(int, int, int) . And Klang agrees . On the other hand, the GCC still does not accept it , stating the same reason for the two viable c'tors.

To make matters worse, this is even more confusing for another observation. If list initialization was used instead, i.e. A a{{1,2,3}}; , then suddenly Clang and GCC accept the code with the initial definition of the class without changes (where there is nothing explicit ).

Which compiler is compatible with A a({1,2,3}); ?

+7
c ++ language-lawyer
source share

No one has answered this question yet.

See similar questions:

21
Invoking an explicit constructor with a braced-init list: ambiguous or not?
sixteen
Very strange overload rejection
0
class call constructor with a closed list of initiators

or similar:

740
Is it possible to call a constructor from another constructor (make a constructor chain) in C ++?
197
Constructor List Initialization Evaluation Order
25
When overload is resolved, choosing a function that uses an ambiguous conversion sequence necessarily leads to poor call formation?
14
Should initialization by a transform function be ambiguous if two candidates have the same qualifications?
6
C ++ copy initialization and direct initialization, strange case
6
gcc and clang both return a call to the move constructor in the snippet below. It's right?
5
Is immediate temporary use of the destructor required?
5
Why is this reference binding poorly formed?
3
pattern type failure (std :: empty as a predicate)
0
Why MSVC and GCC cannot initialize a structure with a default field

All Articles