“default constructor cannot be referenced” in Visual Studio 2015

前端 未结 1 715
青春惊慌失措
青春惊慌失措 2021-02-19 15:28

I am facing a really weird error message in Visual Studio 2015. The following stripped down code:

struct A
{
    A(int val = 0)
    :
        x(val)
    {}

          


        
1条回答
  •  遥遥无期
    2021-02-19 16:11

    This is an Intellisense bug. Both clang and gcc accept this code, also webcompiler an online Visual c++ compiler accepts this code.

    The draft C++14 standard section 12.1 [class.ctor] says a defaulted default constructor for a class is deleted if:

    • X is a union-like class that has a variant member with a non-trivial default constructor,
    • any non-static data member with no brace-or-equal-initializer is of reference type,
    • any non-variant non-static data member of const-qualified type (or array thereof) with no brace-orequal- initializer does not have a user-provided default constructor,
    • X is a union and all of its variant members are of const-qualified type (or array thereof),
    • X is a non-union class and all members of any anonymous union member are of const-qualified type (or array thereof),
    • any potentially constructed subobject, except for a non-static data member with a brace-or-equalinitializer, has class type M (or array thereof) and either M has no default constructor or overload resolution (13.3) as applied to M’s default constructor results in an ambiguity or in a function that is deleted or inaccessible from the defaulted default constructor, or
    • any potentially constructed subobject has a type with a destructor that is deleted or inaccessible from the defaulted default constructor.

    none of which applies here.

    Update

    In the bug report filed by the OP the response was:

    Thank you for reporting this issue. Fix should be available in the next update to Visual Studio 2015.

    0 讨论(0)
提交回复
热议问题