Skip to content

Clang accepts invalid program when default constructor is overloaded with initializer list constructor that is also a default constructor #102157

Open
@ranaanoop

Description

@ranaanoop

The following invalid program is accepted by clang. Demo

#include <initializer_list>

struct C
{ 
    C(){}
    C(std::initializer_list<int> i = {3})
    {
    }  
};

int main()
{
    C d{};   //clang:Ok, gcc:No, MSVC: No, EDG: No
}

This is invalid due to ambiguity between the ctors for () as explained in this thread.

Clang uses the initializer list ctor over the other default ctor which is not the correct behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions