From 3fd91cbd4fe2bcfb7d2db25fe2c2cc2ec2d271b2 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 30 Apr 1999 16:07:03 +0000 Subject: [PATCH] typeck.c (build_const_cast): Tweak last change to handle templates correctly. * typeck.c (build_const_cast): Tweak last change to handle templates correctly. From-SVN: r26712 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/typeck.c | 16 ++++++++-------- gcc/testsuite/g++.old-deja/g++.pt/cast1.C | 7 +++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/cast1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3bb29de5a56..584c9714d42 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 1999-04-30 Mark Mitchell + * typeck.c (build_const_cast): Tweak last change to handle + templates correctly. + * typeck.c (build_const_cast): Disallow use of const_cast to anything but a pointer or reference type. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c01131adec3..ad7f552b1cb 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5633,14 +5633,6 @@ build_const_cast (type, expr) if (type == error_mark_node || expr == error_mark_node) return error_mark_node; - if (!POINTER_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type)) - { - cp_error ("`%T' is not a pointer, reference, or pointer-to-member type", - type); - cp_error ("as required by const_cast"); - return error_mark_node; - } - if (TREE_CODE (expr) == OFFSET_REF) expr = resolve_offset_ref (expr); @@ -5651,6 +5643,14 @@ build_const_cast (type, expr) return t; } + if (!POINTER_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type)) + { + cp_error ("`%T' is not a pointer, reference, or pointer-to-member type", + type); + cp_error ("as required by const_cast"); + return error_mark_node; + } + if (TREE_CODE (type) != REFERENCE_TYPE) { expr = decay_conversion (expr); diff --git a/gcc/testsuite/g++.old-deja/g++.pt/cast1.C b/gcc/testsuite/g++.old-deja/g++.pt/cast1.C new file mode 100644 index 00000000000..e37b1693155 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/cast1.C @@ -0,0 +1,7 @@ +// Build don't link: +// Origin: Mark Mitchell + +template +void f (T t) { + const_cast(t); +} -- 2.30.2