[PATCH] Handle use of default member initializers before end of outermost class

Richard Smith richard at metafoo.co.uk
Tue Oct 21 16:41:13 PDT 2014


On Tue, Oct 21, 2014 at 3:38 PM, Reid Kleckner <rnk at google.com> wrote:

> >>! In D5690#13, @rsmith wrote:
> > Two more things I'd like to see tested:
> >
> > 1: Explicit instantiation of a class should presumably *not* instantiate
> default initializers unless they're actually used by some constructor that
> is explicitly instantiated. For instance:
> >
> >     template<typename T> struct X {
> >       X();
> >       int n = T::error;
> >     };
> >     template struct X<int>; // ok
> >     template<typename T> X<T>::X() {}
> >     template struct X<float>; // error in instantiation of X<float>::n's
> initializer from X<float>::X()
>
> OK, that works.
>
> > 2: Instantiation of a function with a local class should always
> instantiate the default initializers, even if they're not used. For
> instance:
> >
> >     template<typename T> void f() {
> >       struct X {
> >         int n = T::error;
> >       };
> >     }
> >     void g() { f<int>(); } // error
>
> I can probably go add this logic, but what's the reason?


See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1484

================
> Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6194-6195
> @@ +6193,4 @@
> +    : Error<"cannot use defaulted default constructor of %0 within the
> class "
> +            "outside of member functions due to non-static data member "
> +            "initializer for %1">;
> +def err_in_class_initializer_not_yet_parsed_outer_class
> ----------------
> rsmith wrote:
> > "non-static data member initializer" is a term the GCC folks made up; I
> don't like it =) How about:
> >
> >     "... because %1 has an initializer"?
> Sure, but see the other template instantiation note which uses this
> terminology.
>
> http://reviews.llvm.org/D5690
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141021/fe3c7286/attachment.html>


More information about the cfe-commits mailing list