summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-09-05 18:04:21 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-09-05 18:04:21 +0000
commita610fc5e58c8bc04feee4453adde81eb1fcc1b9b (patch)
tree6985ef10a548d692a06e263e44d798c0302163e0
parentf6fbe1972d5a3005266b385749eae2349f886585 (diff)
downloadgcc-a610fc5e58c8bc04feee4453adde81eb1fcc1b9b.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71115 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/call.c16
-rw-r--r--gcc/cp/pt.c3
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/expr/static_cast4.C11
-rw-r--r--gcc/testsuite/g++.dg/template/crash9.C12
6 files changed, 57 insertions, 2 deletions
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 <mark@codesourcery.com>
+
+ 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 <nathan@codesourcery.com>
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 <mark@codesourcery.com>
+
+ 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 <pinskia@physics.uc.edu>
* 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<C>(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();
+}
+