Commit 2f8ec491 by Mark Mitchell Committed by Mark Mitchell

* typeck.c (build_const_cast): Tighten checks for legality.

From-SVN: r26753
parent d750f6f7
1999-05-03 Mark Mitchell <mark@codesourcery.com>
* typeck.c (build_const_cast): Tighten checks for legality.
1999-05-02 Martin von Lwis <loewis@informatik.hu-berlin.de> 1999-05-02 Martin von Lwis <loewis@informatik.hu-berlin.de>
* init.c (build_member_call): Lookup names coming from * init.c (build_member_call): Lookup names coming from
......
...@@ -5643,11 +5643,17 @@ build_const_cast (type, expr) ...@@ -5643,11 +5643,17 @@ build_const_cast (type, expr)
return t; return t;
} }
if (!POINTER_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type)) if (!POINTER_TYPE_P (type))
{ {
cp_error ("`%T' is not a pointer, reference, or pointer-to-member type", cp_error ("`%T' is not a pointer, reference, or pointer-to-data-member type",
type); type);
cp_error ("as required by const_cast"); cp_error ("as required by const_cast");
}
else if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
{
cp_error ("`%T' is a pointer or reference to a function type",
type);
cp_error ("which is forbidden by const_cast");
return error_mark_node; return error_mark_node;
} }
......
...@@ -7,5 +7,11 @@ struct A { ...@@ -7,5 +7,11 @@ struct A {
int main() int main()
{ {
A a; A a;
typedef void (A::*F)();
F p;
const_cast<const A>(a); // ERROR - const_cast requires pointer/ref types const_cast<const A>(a); // ERROR - const_cast requires pointer/ref types
const_cast<F>(p); // ERROR - const_cast requires pointer/ref types
const_cast<int (*)()>(&main); // ERROR - function type in const_cast
const_cast<int (&)()>(main); // ERROR - function type in const_cast
} }
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