From 0949f72302592c9daf2a114fd89a858383ddf7ad Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 12 Jan 2001 09:47:23 +0000 Subject: [PATCH] typeck.c (build_c_cast): Do template processing earlier. cp: * typeck.c (build_c_cast): Do template processing earlier. Always pedwarn on array casts. testsuite: * g++.old-deja/g++.pt/cast2.C: New test. From-SVN: r38941 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck.c | 19 +++++++++--------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.old-deja/g++.pt/cast2.C | 32 +++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/cast2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1297b2f..fd6caef 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2001-01-12 Nathan Sidwell + * typeck.c (build_c_cast): Do template processing earlier. + Always pedwarn on array casts. + +2001-01-12 Nathan Sidwell + * friend.c (make_friend_class): Make sure a templated class is actually a template. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a10f1d4..6a05ef9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5349,6 +5349,13 @@ build_c_cast (type, expr) if (type == error_mark_node || expr == error_mark_node) return error_mark_node; + if (processing_template_decl) + { + tree t = build_min (CAST_EXPR, type, + tree_cons (NULL_TREE, value, NULL_TREE)); + return t; + } + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */ if (TREE_CODE (type) != REFERENCE_TYPE @@ -5365,13 +5372,12 @@ build_c_cast (type, expr) NIHCL uses it. It is not valid ISO C++ however. */ if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE) { - if (pedantic) - pedwarn ("ISO C++ forbids casting to an array type"); + cp_pedwarn ("ISO C++ forbids casting to an array type `%T'", type); type = build_pointer_type (TREE_TYPE (type)); } else { - error ("ISO C++ forbids casting to an array type"); + cp_error ("ISO C++ forbids casting to an array type `%T'", type); return error_mark_node; } } @@ -5383,13 +5389,6 @@ build_c_cast (type, expr) return error_mark_node; } - if (processing_template_decl) - { - tree t = build_min (CAST_EXPR, type, - tree_cons (NULL_TREE, value, NULL_TREE)); - return t; - } - if (TREE_CODE (type) == VOID_TYPE) { /* Conversion to void does not cause any of the normal function to diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c413ab..31a45bf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2001-01-12 Nathan Sidwell + * g++.old-deja/g++.pt/cast2.C: New test. + +2001-01-12 Nathan Sidwell + * g++.old-deja/g++.pt/friend47.C: New test. 2001-01-11 Nathan Sidwell diff --git a/gcc/testsuite/g++.old-deja/g++.pt/cast2.C b/gcc/testsuite/g++.old-deja/g++.pt/cast2.C new file mode 100644 index 0000000..fb0a260 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/cast2.C @@ -0,0 +1,32 @@ +// Build don't link: + +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 10 Jan 2001 + +// Bug 1588. We ICE'd on reparsing an absdcl as a cast inside a template +// function. + +class A { +public: + template void f(void *CLUTp); +}; + +template void A::f(void *CLUTp) +{ + void *CLUT; + + CLUT = (unsigned char [3][256])CLUTp; // ERROR - cast to array + + return; +} + + +int main() +{ + A myobj; + unsigned char t[3][256]; + + myobj.f(t); + + return 0; +} -- 2.7.4