From ceeae2d125cce0f03ad7d47f62c3f82ff2af78fd Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 5 Sep 2003 18:04:21 +0000 Subject: [PATCH] re PR c++/12163 (static_cast + explicit ctor regression) PR c++/12163 * call.c (perform_direct_initialization): Correct logic for direct-initialization of a class type. PR c++/12146 * pt.c (lookup_template_function): Robustify. PR c++/12163 * g++.dg/expr/static_cast4.C: New test. PR c++/12146 * g++.dg/template/crash9.C: New test. From-SVN: r71115 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/call.c | 16 +++++++++++++++- gcc/cp/pt.c | 3 ++- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/expr/static_cast4.C | 11 +++++++++++ gcc/testsuite/g++.dg/template/crash9.C | 12 ++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/expr/static_cast4.C create mode 100644 gcc/testsuite/g++.dg/template/crash9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1f7892735a9..7840de47bf7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2003-09-05 Mark Mitchell + + PR c++/12163 + * call.c (perform_direct_initialization): Correct logic for + direct-initialization of a class type. + + PR c++/12146 + * pt.c (lookup_template_function): Robustify. + 2003-09-05 Nathan Sidwell PR c++/11922 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index fee2357b07c..cc03adc6f57 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5951,7 +5951,8 @@ perform_implicit_conversion (tree type, tree expr) /* Convert EXPR to TYPE (as a direct-initialization) if that is permitted. If the conversion is valid, the converted expression is - returned. Otherwise, NULL_TREE is returned. */ + returned. Otherwise, NULL_TREE is returned, except in the case + that TYPE is a class type; in that case, an error is issued. */ tree perform_direct_initialization_if_possible (tree type, tree expr) @@ -5960,6 +5961,19 @@ perform_direct_initialization_if_possible (tree type, tree expr) if (type == error_mark_node || error_operand_p (expr)) return error_mark_node; + /* [dcl.init] + + If the destination type is a (possibly cv-qualified) class type: + + -- If the initialization is direct-initialization ..., + constructors are considered. ... If no constructor applies, or + the overload resolution is ambiguous, the initialization is + ill-formed. */ + if (CLASS_TYPE_P (type)) + return build_special_member_call (NULL_TREE, complete_ctor_identifier, + build_tree_list (NULL_TREE, expr), + TYPE_BINFO (type), + LOOKUP_NORMAL); conv = implicit_conversion (type, TREE_TYPE (expr), expr, LOOKUP_NORMAL); if (!conv || ICS_BAD_FLAG (conv)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f8f38f0a87c..8169cf33c8a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3854,7 +3854,8 @@ lookup_template_function (tree fns, tree arglist) return error_mark_node; my_friendly_assert (!arglist || TREE_CODE (arglist) == TREE_VEC, 20030726); - if (fns == NULL_TREE) + if (fns == NULL_TREE + || TREE_CODE (fns) == FUNCTION_DECL) { error ("non-template used as template"); return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b4de177bd5..724bdef2112 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2003-09-05 Mark Mitchell + + PR c++/12163 + * g++.dg/expr/static_cast4.C: New test. + + PR c++/12146 + * g++.dg/template/crash9.C: New test. + 2003-09-05 Andrew Pinski * g++.old-deja/g++.ext/pretty2.C: Update for change diff --git a/gcc/testsuite/g++.dg/expr/static_cast4.C b/gcc/testsuite/g++.dg/expr/static_cast4.C new file mode 100644 index 00000000000..cea7f487393 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/static_cast4.C @@ -0,0 +1,11 @@ +class C { +public: + explicit C(int) {} +}; + +int main() +{ + int i = 0; + static_cast(i); + return 0; +} diff --git a/gcc/testsuite/g++.dg/template/crash9.C b/gcc/testsuite/g++.dg/template/crash9.C new file mode 100644 index 00000000000..7a568fe054a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash9.C @@ -0,0 +1,12 @@ +struct A { }; +struct B { }; + +A f(const B & b) { + return A(); +} + +template<> +B f(const A & a) { // { dg-error "" } + return B(); +} +