This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c++/33558
- From: Giovanni dot Funchal at imag dot fr
- To: gcc-patches at gcc dot gnu dot org
- Cc: gafunchal at gmail dot com
- Date: Sat, 09 Jan 2010 13:23:45 +0100
- Subject: [PATCH] Fix PR c++/33558
C++ standard 7.1.1 says that 'mutable' cannot be applied to reference
members, yet g++ accepts it. This patch fixes bug #33558.
-- Giovanni
for gcc/cp/ChangeLog
from Giovanni Funchal <gafunchal@gmail.com>
PR c++/33558
* decl.c (grokdeclarator): Check for mutable reference members
for gcc/testsuite/ChangeLog
from Giovanni Funchal <gafunchal@gmail.com>
PR c++/33558
* g++.dg/other/pr33558.C: New
Index: gcc/testsuite/g++.dg/other/pr33558.C
===================================================================
--- gcc/testsuite/g++.dg/other/pr33558.C (revision 0)
+++ gcc/testsuite/g++.dg/other/pr33558.C (revision 0)
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+class X {
+ mutable int &q; /* { dg-error "cannot be declared 'mutable'" } */
+};
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 155755)
+++ gcc/cp/decl.c (working copy)
@@ -8897,6 +8897,11 @@ grokdeclarator (const cp_declarator *declarator,
error ("const %qs cannot be declared %<mutable%>", name);
storage_class = sc_none;
}
+ else if (TREE_CODE (type) == REFERENCE_TYPE)
+ {
+ error ("reference member %qs cannot be declared %<mutable%>", name);
+ storage_class = sc_none;
+ }
}
/* If this is declaring a typedef name, return a TYPE_DECL. */