re PR c++/65579 ([C++11] gcc requires definition of a static constexpr member even...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 6 Nov 2017 17:45:55 +0000 (17:45 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 6 Nov 2017 17:45:55 +0000 (17:45 +0000)
/cp
2017-11-06  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/65579
* decl2.c (finish_static_data_member_decl): If there's an initializer,
complete the type and re-apply the quals.

/testsuite
2017-11-06  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/65579
* g++.dg/cpp0x/constexpr-template11.C: New.

From-SVN: r254461

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C [new file with mode: 0644]

index bb90b5ac4da75f993f24228e0aba014dd5c5fdb3..2a6143a2f472af2ac9e0aae237da6350f5828089 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-06  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/65579
+       * decl2.c (finish_static_data_member_decl): If there's an initializer,
+       complete the type and re-apply the quals.
+
 2017-11-06  Martin Liska  <mliska@suse.cz>
 
        PR middle-end/82404
index a23b96c53e734cd4661a83a7f5626ff51bca0e34..0b183085e0e3b605df8aa5ee88402d22792c8fbb 100644 (file)
@@ -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 edb3797cc1d169e223b7f00a7b7dc165c9a189a2..b8f7d931ef3e1425249d79d9673618650cd82979 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-06  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/65579
+       * g++.dg/cpp0x/constexpr-template11.C: New.
+
 2017-11-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/82838
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template11.C
new file mode 100644 (file)
index 0000000..0ad4908
--- /dev/null
@@ -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;
+}