aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2013-08-22 16:30:08 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2013-08-22 16:30:08 +0000
commit42306d73c877d8f52eb80c0a724d27a40f25e2fb (patch)
tree78021d573b580d4f6d3cd6707a84991ccb6fd12a /gcc/cp/class.c
parent7bf4274ea7e77984c576c691aa5c855086280930 (diff)
downloadgcc-42306d73c877d8f52eb80c0a724d27a40f25e2fb.zip
gcc-42306d73c877d8f52eb80c0a724d27a40f25e2fb.tar.gz
gcc-42306d73c877d8f52eb80c0a724d27a40f25e2fb.tar.bz2
re PR c++/56380 (Const/reference mutable members are not always rejected in class templates)
/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
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 2f08d5f..596b13d 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -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. */