default argument, gcc vs clang

前端 未结 3 1685
余生分开走
余生分开走 2021-01-01 16:27

Code looks like:

struct Foo {
    Foo(const char *);
};

Foo::Foo(const char *str = 0)
{
}

VS 2013 and gcc 4.8.0 accept such code, while cl

3条回答
  •  无人及你
    2021-01-01 17:11

    I would say CLANG is right. The standard says (12.1.5 for the both old and new versions of the standard):

    A default constructor for a class X is a constructor of class X that can be called without an argument

    Adding the default value to the only argument of the constructor definitely makes it possible to call it without arguments, thus making it a default one. Also, 8.3.6 says (emphasis mine):

    A default argument expression shall be specified only in the parameter-declaration-clause of a function declaration <...>

提交回复
热议问题