From 9a4312bddf98c17130c20cab9d5fe1f18bfe7fb4 Mon Sep 17 00:00:00 2001 From: lerdsuwa Date: Sat, 4 Dec 2004 06:45:13 +0000 Subject: [PATCH] PR c++/17011, c++/17971 * pt.c (tsubst_copy) : Check and diagnose invalid field. (tsubst_copy_and_build) : Check error_mark_node after member substitution. * semantics.c (finish_id_expression): Call finish_non_static_data_member for non-dependent FIELD_DECL. * g++.dg/template/error15.C: Adjust expected error. * g++.dg/template/instantiate3.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91720 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/pt.c | 15 +++++++++++++-- gcc/cp/semantics.c | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/template/error15.C | 6 +++--- gcc/testsuite/g++.dg/template/instantiate3.C | 2 +- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7ce41e4..0ffc52d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2004-12-04 Kriang Lerdsuwanakij + + PR c++/17011, c++/17971 + * pt.c (tsubst_copy) : Check and diagnose + invalid field. + (tsubst_copy_and_build) : Check + error_mark_node after member substitution. + * semantics.c (finish_id_expression): Call + finish_non_static_data_member for non-dependent FIELD_DECL. + 2004-12-03 Nathan Sidwell PR c++/18782 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a0cc45c..2a1a5b3 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7702,7 +7702,16 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) ctx = tsubst_aggr_type (DECL_CONTEXT (t), args, complain, in_decl, /*entering_scope=*/1); if (ctx != DECL_CONTEXT (t)) - return lookup_field (ctx, DECL_NAME (t), 0, false); + { + tree r = lookup_field (ctx, DECL_NAME (t), 0, false); + if (!r) + { + if (complain & tf_error) + error ("using invalid field %qD", t); + return error_mark_node; + } + return r; + } } return t; @@ -8693,7 +8702,9 @@ tsubst_copy_and_build (tree t, else member = tsubst_copy (member, args, complain, in_decl); - if (!CLASS_TYPE_P (TREE_TYPE (object))) + if (member == error_mark_node) + return error_mark_node; + else if (!CLASS_TYPE_P (TREE_TYPE (object))) { if (TREE_CODE (member) == BIT_NOT_EXPR) return finish_pseudo_destructor_expr (object, diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2cd78eb..7f399b4 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2571,6 +2571,12 @@ finish_id_expression (tree id_expression, if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) return decl; + /* The same is true for FIELD_DECL, but we also need to + make sure that the syntax is correct. */ + else if (TREE_CODE (decl) == FIELD_DECL) + return finish_non_static_data_member + (decl, current_class_ref, + /*qualifying_scope=*/NULL_TREE); return id_expression; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eba1f1e..d44121c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-12-04 Kriang Lerdsuwanakij + + PR c++/17011, c++/17971 + * g++.dg/template/error15.C: Adjust expected error. + * g++.dg/template/instantiate3.C: Likewise. + 2004-12-03 Janis Johnson * gcc.dg/altivec-18.c: Fix for darwin diff --git a/gcc/testsuite/g++.dg/template/error15.C b/gcc/testsuite/g++.dg/template/error15.C index 5a1a322..6bd1f77 100644 --- a/gcc/testsuite/g++.dg/template/error15.C +++ b/gcc/testsuite/g++.dg/template/error15.C @@ -11,14 +11,14 @@ protected: A a; // { dg-error "" } - void f(const A * a1 = &a); + void f(const A * a1 = &a); // { dg-error "this location" } void g(void); }; template void B::g(void) { - f(); // { dg-error "" } + f(); } -template class B; // { dg-error "" } +template class B; diff --git a/gcc/testsuite/g++.dg/template/instantiate3.C b/gcc/testsuite/g++.dg/template/instantiate3.C index 3ad8b95..4644fd0 100644 --- a/gcc/testsuite/g++.dg/template/instantiate3.C +++ b/gcc/testsuite/g++.dg/template/instantiate3.C @@ -10,7 +10,7 @@ template struct ACE_Cleanup_Adapter { TYPE &object () - { return object_; } // { dg-error "not declared|reported" } + { return object_; } // { dg-error "invalid" } TYPE object_; // { dg-error "incomplete type" } }; -- 2.7.4