PR c++/12163
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Sep 2003 18:04:21 +0000 (18:04 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Sep 2003 18:04:21 +0000 (18:04 +0000)
* 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

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/static_cast4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash9.C [new file with mode: 0644]

index 1f78927..7840de4 100644 (file)
@@ -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
index fee2357..cc03adc 100644 (file)
@@ -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))
index f8f38f0..8169cf3 100644 (file)
@@ -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;
index 6b4de17..724bdef 100644 (file)
@@ -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 (file)
index 0000000..cea7f48
--- /dev/null
@@ -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 (file)
index 0000000..7a568fe
--- /dev/null
@@ -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();
+}
+