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

Reid Kleckner rnk at google.com
Tue Oct 21 15:38:48 PDT 2014


>>! 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?

================
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






More information about the cfe-commits mailing list