diff options
author | Mark Mitchell <mark@codesourcery.com> | 1999-05-03 15:04:58 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 1999-05-03 15:04:58 +0000 |
commit | 2f8ec491ba5250824d0375d8b8e488c2cd689764 (patch) | |
tree | fc157753e22ebbe959582e73fce9776fc3e85c3d /gcc | |
parent | d750f6f780b3d70bc78c36daa0c896e335115654 (diff) | |
download | gcc-2f8ec491ba5250824d0375d8b8e488c2cd689764.zip gcc-2f8ec491ba5250824d0375d8b8e488c2cd689764.tar.gz gcc-2f8ec491ba5250824d0375d8b8e488c2cd689764.tar.bz2 |
* typeck.c (build_const_cast): Tighten checks for legality.
From-SVN: r26753
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.other/cast2.C | 6 |
3 files changed, 18 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2310476..ebad880 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index ad7f552..d65479b 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 cd49640..80cf7dc 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<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 } |