C++: initialization of auto&& with the ternary operator leads to the copy constructor call on MSVC

46 Views Asked by At
int main()
{
    struct STR
    {
       STR() {}
       STR(const STR&) = delete;
    };

    bool b = true;
    auto&& a0 = b ? STR{} : STR{};
}

The following code successfully compiles on the latest versions of gcc and clang but fails on MSVC:

error C2280: 'main::STR::STR(const main::STR &)': attempting to reference a deleted function  
note: see declaration of 'main::STR::STR'  
note: 'main::STR::STR(const main::STR &)': function was explicitly deleted

Can it be considered as an MSVC bug?

0

There are 0 best solutions below