re PR c++/56380 (Const/reference mutable members are not always rejected in class...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 22 Aug 2013 16:30:08 +0000 (16:30 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 22 Aug 2013 16:30:08 +0000 (16:30 +0000)
/cp
2013-08-22  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/56380
* class.c (check_field_decls): Check for const mutable and const
reference data members.

/testsuite
2013-08-22  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/56380
* g++.dg/template/error54.C: New.

From-SVN: r201925

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/error54.C [new file with mode: 0644]

index 4624e7395c642c04269e9b6d3c2597fe06d5b2a0..92884a0834ce30608eb77b79f7c15782f809829a 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-22  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/56380
+       * class.c (check_field_decls): Check for const mutable and const
+       reference data members.
+
 2013-08-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        * error.c (init_error): Remove calls to pp_construct and
index 2f08d5f0c7c1b5b823a16b9f77e56e1aeaebe579..596b13d2695fe5d664fa581efa4b0d555d52becf 100644 (file)
@@ -3500,6 +3500,22 @@ check_field_decls (tree t, tree *access_decls,
       if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
        CLASSTYPE_HAS_MUTABLE (t) = 1;
 
+      if (DECL_MUTABLE_P (x))
+       {
+         if (CP_TYPE_CONST_P (type))
+           {
+             error ("member %q+D cannot be declared both %<const%> "
+                    "and %<mutable%>", x);
+             continue;
+           }
+         if (TREE_CODE (type) == REFERENCE_TYPE)
+           {
+             error ("member %q+D cannot be declared as a %<mutable%> "
+                    "reference", x);
+             continue;
+           }
+       }
+
       if (! layout_pod_type_p (type))
        /* DR 148 now allows pointers to members (which are POD themselves),
           to be allowed in POD structs.  */
index c8786257da42fcf7486a1dce68276e6478aa3497..65d3e23d8ac34a6bd3cb31f922c803cd26a04892 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-22  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/56380
+       * g++.dg/template/error54.C: New.
+
 2013-08-22  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/58185
diff --git a/gcc/testsuite/g++.dg/template/error54.C b/gcc/testsuite/g++.dg/template/error54.C
new file mode 100644 (file)
index 0000000..2933bb5
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/56380
+
+template <typename T>
+struct X {
+  X();
+  mutable T x;  // { dg-error "cannot be declared" }
+};
+
+X<const int> a; // { dg-message "required from here" }
+X<int&> b;      // { dg-message "required from here" }