From: Mark Mitchell Date: Mon, 3 May 1999 15:04:58 +0000 (+0000) Subject: * typeck.c (build_const_cast): Tighten checks for legality. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2f8ec491ba5250824d0375d8b8e488c2cd689764;p=gcc.git * typeck.c (build_const_cast): Tighten checks for legality. From-SVN: r26753 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 231047669dd..ebad880812a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +1999-05-03 Mark Mitchell + + * typeck.c (build_const_cast): Tighten checks for legality. + 1999-05-02 Martin von Löwis * init.c (build_member_call): Lookup names coming from diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index ad7f552b1cb..d65479b4033 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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; } diff --git a/gcc/testsuite/g++.old-deja/g++.other/cast2.C b/gcc/testsuite/g++.old-deja/g++.other/cast2.C index cd496405c53..80cf7dc1864 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/cast2.C +++ b/gcc/testsuite/g++.old-deja/g++.other/cast2.C @@ -7,5 +7,11 @@ struct A { int main() { A a; + typedef void (A::*F)(); + F p; + const_cast(a); // ERROR - const_cast requires pointer/ref types + const_cast(p); // ERROR - const_cast requires pointer/ref types + const_cast(&main); // ERROR - function type in const_cast + const_cast(main); // ERROR - function type in const_cast }