[cfe-dev] defaulted default constructor with initializer

Richard Smith richard at metafoo.co.uk
Thu Apr 16 16:48:32 PDT 2015


On Thu, Apr 16, 2015 at 10:16 AM, Kal <b17c0de at gmail.com> wrote:

>  Consider this code:
>
> class A {
> public:
>   struct I {
>     int i = 0;
>   };
>   A(I i = {}) {}
> };
>
> With clang 3.6 this doesn't compile:
> 4 : error: cannot use defaulted default constructor of 'I' within 'A'
> outside of member functions because 'i' has an initializer
>
> But if I change the code to
>
> class A {
> public:
>   struct I {
>     int i = 0;
>     I() {}
>   };
>   A(I i = {}) {}
> };
>
> then the code compiles. Why is this so? Aren't these equivalent?
>

They're not equivalent. The implicit constructor for A::I also has a
deduced exception specification, and computing that exception specification
requires the initializer for 'A::i' to have already been parsed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150416/59fb70b9/attachment.html>


More information about the cfe-dev mailing list