[cfe-dev] Reason for Diagnostic on default ctors redeclaration

Richard Smith richard at metafoo.co.uk
Tue May 14 17:23:10 PDT 2013


On Tue, May 14, 2013 at 4:30 PM, John McCall <rjmccall at apple.com> wrote:

> On May 14, 2013, at 3:29 PM, Alireza Moshtaghi <
> Alireza.Moshtaghi at synopsys.com> wrote:
> > g++ accepts this code ,  but clang generates:
> >   error1.cpp:5:12:
> >   error: addition of default argument on redeclaration makes this
> >          constructor a default constructor
> > “
> > struct XX {
> >     int a;
> >     XX(int);
> > };
> > XX::XX(int c = 5) : a(c) { }
> > “
> > Question: where does this requirement come from ?
>
> DR1344 is a defect report reported to the C++ standards committee:
>   http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1344
>
> We expect the committee to make some sort of modification here and
> have pre-emptively locked things down to reserve more flexibility to
> respond to whatever the committee does.
>
> The idea is that the presence of certain special members affects core
> properties of a class type, like whether it's POD or trivially copyable.
> Deciding these properties should not require whole-program knowledge;
> it's important for us to be able to deduce them just from the class
> definition.
> The really problematic case is turning a "normal" constructor into a copy
> or move constructor by adding default arguments, but IIRC introducing a
> default constructor was also problematic.
>
> The fix is that you should put the default argument in the initial
> declaration
> of the constructor.
>

This was last discussed by WG21 at the Bloomington meeting. Notes from
there:

  "Consensus: Make this ill-formed as suggested in the write-up. Core issue
1344. Priority 0, Doug drafting."

So CWG has agreed (in principle) that this should be ill-formed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130514/1e5a678d/attachment.html>


More information about the cfe-dev mailing list