Commit fabb00fc by Volker Reichelt Committed by Volker Reichelt

typeck2.c (readonly_error): Always emit a hard error.

	* typeck2.c (readonly_error): Always emit a hard error.
	Remove last argument.
	* cp-tree.h (readonly_error): Adjust prototype.
	* semantics.c (finish_asm_stmt): Adjust call to readonly_error.
	* typeck.c (build_unary_op): Likewise.
	(build_modify_expr): Likewise.

From-SVN: r122541
parent 2881894e
2007-03-05 Volker Reichelt <reichelt@netcologne.de>
* typeck2.c (readonly_error): Always emit a hard error.
Remove last argument.
* cp-tree.h (readonly_error): Adjust prototype.
* semantics.c (finish_asm_stmt): Adjust call to readonly_error.
* typeck.c (build_unary_op): Likewise.
(build_modify_expr): Likewise.
2007-03-04 Simon Martin <simartin@users.sourceforge.net> 2007-03-04 Simon Martin <simartin@users.sourceforge.net>
PR c++/30895 PR c++/30895
......
...@@ -4602,7 +4602,7 @@ extern void cxx_incomplete_type_error (tree, tree); ...@@ -4602,7 +4602,7 @@ extern void cxx_incomplete_type_error (tree, tree);
(cxx_incomplete_type_diagnostic ((V), (T), 0)) (cxx_incomplete_type_diagnostic ((V), (T), 0))
extern tree error_not_base_type (tree, tree); extern tree error_not_base_type (tree, tree);
extern tree binfo_or_else (tree, tree); extern tree binfo_or_else (tree, tree);
extern void readonly_error (tree, const char *, int); extern void readonly_error (tree, const char *);
extern void complete_type_check_abstract (tree); extern void complete_type_check_abstract (tree);
extern int abstract_virtuals_error (tree, tree); extern int abstract_virtuals_error (tree, tree);
......
...@@ -1246,7 +1246,7 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands, ...@@ -1246,7 +1246,7 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands,
effectively const. */ effectively const. */
|| (CLASS_TYPE_P (TREE_TYPE (operand)) || (CLASS_TYPE_P (TREE_TYPE (operand))
&& C_TYPE_FIELDS_READONLY (TREE_TYPE (operand))))) && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
readonly_error (operand, "assignment (via 'asm' output)", 0); readonly_error (operand, "assignment (via 'asm' output)");
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
oconstraints[i] = constraint; oconstraints[i] = constraint;
......
...@@ -4205,8 +4205,7 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert) ...@@ -4205,8 +4205,7 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
|| TREE_READONLY (arg)) || TREE_READONLY (arg))
readonly_error (arg, ((code == PREINCREMENT_EXPR readonly_error (arg, ((code == PREINCREMENT_EXPR
|| code == POSTINCREMENT_EXPR) || code == POSTINCREMENT_EXPR)
? "increment" : "decrement"), ? "increment" : "decrement"));
0);
{ {
tree inc; tree inc;
...@@ -5780,7 +5779,7 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs) ...@@ -5780,7 +5779,7 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
effectively const. */ effectively const. */
|| (CLASS_TYPE_P (lhstype) || (CLASS_TYPE_P (lhstype)
&& C_TYPE_FIELDS_READONLY (lhstype)))) && C_TYPE_FIELDS_READONLY (lhstype))))
readonly_error (lhs, "assignment", 0); readonly_error (lhs, "assignment");
/* If storing into a structure or union member, it has probably been /* If storing into a structure or union member, it has probably been
given type `int'. Compute the type that would go with the actual given type `int'. Compute the type that would go with the actual
......
...@@ -68,20 +68,12 @@ binfo_or_else (tree base, tree type) ...@@ -68,20 +68,12 @@ binfo_or_else (tree base, tree type)
} }
/* According to ARM $7.1.6, "A `const' object may be initialized, but its /* According to ARM $7.1.6, "A `const' object may be initialized, but its
value may not be changed thereafter. Thus, we emit hard errors for these, value may not be changed thereafter. */
rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For
example, conversions to references.) */
void void
readonly_error (tree arg, const char* string, int soft) readonly_error (tree arg, const char* string)
{ {
const char *fmt; const char *fmt;
void (*fn) (const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2);
if (soft)
fn = pedwarn;
else
fn = error;
if (TREE_CODE (arg) == COMPONENT_REF) if (TREE_CODE (arg) == COMPONENT_REF)
{ {
...@@ -89,7 +81,7 @@ readonly_error (tree arg, const char* string, int soft) ...@@ -89,7 +81,7 @@ readonly_error (tree arg, const char* string, int soft)
fmt = "%s of data-member %qD in read-only structure"; fmt = "%s of data-member %qD in read-only structure";
else else
fmt = "%s of read-only data-member %qD"; fmt = "%s of read-only data-member %qD";
(*fn) (fmt, string, TREE_OPERAND (arg, 1)); error (fmt, string, TREE_OPERAND (arg, 1));
} }
else if (TREE_CODE (arg) == VAR_DECL) else if (TREE_CODE (arg) == VAR_DECL)
{ {
...@@ -99,21 +91,21 @@ readonly_error (tree arg, const char* string, int soft) ...@@ -99,21 +91,21 @@ readonly_error (tree arg, const char* string, int soft)
fmt = "%s of constant field %qD"; fmt = "%s of constant field %qD";
else else
fmt = "%s of read-only variable %qD"; fmt = "%s of read-only variable %qD";
(*fn) (fmt, string, arg); error (fmt, string, arg);
} }
else if (TREE_CODE (arg) == PARM_DECL) else if (TREE_CODE (arg) == PARM_DECL)
(*fn) ("%s of read-only parameter %qD", string, arg); error ("%s of read-only parameter %qD", string, arg);
else if (TREE_CODE (arg) == INDIRECT_REF else if (TREE_CODE (arg) == INDIRECT_REF
&& TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
&& (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
|| TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL)) || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
(*fn) ("%s of read-only reference %qD", string, TREE_OPERAND (arg, 0)); error ("%s of read-only reference %qD", string, TREE_OPERAND (arg, 0));
else if (TREE_CODE (arg) == RESULT_DECL) else if (TREE_CODE (arg) == RESULT_DECL)
(*fn) ("%s of read-only named return value %qD", string, arg); error ("%s of read-only named return value %qD", string, arg);
else if (TREE_CODE (arg) == FUNCTION_DECL) else if (TREE_CODE (arg) == FUNCTION_DECL)
(*fn) ("%s of function %qD", string, arg); error ("%s of function %qD", string, arg);
else else
(*fn) ("%s of read-only location", string); error ("%s of read-only location", string);
} }
......
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