Hi,

On 03/11/2017 18:56, Jason Merrill wrote:
Looking at the code again, it seems that the problem is the difference
between start_decl_1 and grokfield, in that the former has

   /* If an explicit initializer is present, or if this is a definition
      of an aggregate, then we need a complete type at this point.
      (Scalars are always complete types, so there is nothing to
      check.)  This code just sets COMPLETE_P; errors (if necessary)
      are issued below.  */
   if ((initialized || aggregate_definition_p)
       && !complete_p
       && COMPLETE_TYPE_P (complete_type (type)))
     {
       complete_p = true;
       /* We will not yet have set TREE_READONLY on DECL if the type
          was "const", but incomplete, before this point.  But, now, we
          have a complete type, so we can try again.  */
       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     }

and grokfield/finish_static_data_member_decl don't.  How about
completing the type and re-applying the quals in
finish_static_data_member_decl if there's an initializer?  Your most
recent patch ought to work, but is less parallel.  Sorry for the
churn.
No problem, I learned something! Anyway, yes, the below is passing testing, shall we go ahead with it?

Thanks,
Paolo.

///////////////////////
Index: cp/decl2.c
===================================================================
--- cp/decl2.c  (revision 254365)
+++ cp/decl2.c  (working copy)
@@ -787,6 +787,15 @@ finish_static_data_member_decl (tree decl,
       && TYPE_DOMAIN (TREE_TYPE (decl)) == NULL_TREE)
     SET_VAR_HAD_UNKNOWN_BOUND (decl);
 
+  if (init)
+    {
+      /* Similarly to start_decl_1, we want to complete the type in order
+        to do the right thing in cp_apply_type_quals_to_decl, possibly
+        clear TYPE_QUAL_CONST (c++/65579).  */
+      tree type = TREE_TYPE (decl) = complete_type (TREE_TYPE (decl));
+      cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
+    }
+
   cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
 }
 
Index: testsuite/g++.dg/cpp0x/constexpr-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-template11.C       (nonexistent)
+++ testsuite/g++.dg/cpp0x/constexpr-template11.C       (working copy)
@@ -0,0 +1,16 @@
+// PR c++/65579
+// { dg-do link { target c++11 } }
+
+template <typename>
+struct S {
+    int i;
+};
+
+struct T {
+  static constexpr S<int> s = { 1 };
+};
+
+int main()
+{
+  return T::s.i;
+}

Reply via email to