Commit 42306d73 by Paolo Carlini Committed by Paolo Carlini

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
parent 7bf4274e
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
......
......@@ -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. */
......
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
......
// 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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment