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

From-SVN: r26753
This commit is contained in:
Mark Mitchell 1999-05-03 15:04:58 +00:00 committed by Mark Mitchell
parent d750f6f780
commit 2f8ec491ba
3 changed files with 18 additions and 2 deletions

View file

@ -1,3 +1,7 @@
1999-05-03 Mark Mitchell <mark@codesourcery.com>
* typeck.c (build_const_cast): Tighten checks for legality.
1999-05-02 Martin von Löwis <loewis@informatik.hu-berlin.de>
* init.c (build_member_call): Lookup names coming from

View file

@ -5643,11 +5643,17 @@ build_const_cast (type, expr)
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);
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;
}

View file

@ -7,5 +7,11 @@ struct A {
int main()
{
A a;
typedef void (A::*F)();
F p;
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
}