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

Richard Smith richard at metafoo.co.uk
Thu Oct 16 16:30:04 PDT 2014


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()

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

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

http://reviews.llvm.org/D5690






More information about the cfe-commits mailing list