This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR c++/12163, c++/12146


This patch fixes a couple of 3.3.2/3.4 regressions.

Tested on i686-pc-linux-gnu, applied on the branch and on the
mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

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  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.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.430
diff -c -5 -p -r1.430 call.c
*** cp/call.c	5 Sep 2003 08:24:18 -0000	1.430
--- cp/call.c	5 Sep 2003 18:00:16 -0000
*************** perform_implicit_conversion (tree type, 
*** 5949,5967 ****
    return convert_like (conv, 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.  */
  
  tree
  perform_direct_initialization_if_possible (tree type, tree expr)
  {
    tree conv;
    
    if (type == error_mark_node || error_operand_p (expr))
      return error_mark_node;
    conv = implicit_conversion (type, TREE_TYPE (expr), expr,
  			      LOOKUP_NORMAL);
    if (!conv || ICS_BAD_FLAG (conv))
      return NULL_TREE;
    return convert_like_real (conv, expr, NULL_TREE, 0, 0, 
--- 5949,5981 ----
    return convert_like (conv, 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, 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)
  {
    tree conv;
    
    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))
      return NULL_TREE;
    return convert_like_real (conv, expr, NULL_TREE, 0, 0, 
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.774
diff -c -5 -p -r1.774 pt.c
*** cp/pt.c	5 Sep 2003 08:38:42 -0000	1.774
--- cp/pt.c	5 Sep 2003 18:00:24 -0000
*************** lookup_template_function (tree fns, tree
*** 3852,3862 ****
  
    if (fns == error_mark_node || arglist == error_mark_node)
      return error_mark_node;
  
    my_friendly_assert (!arglist || TREE_CODE (arglist) == TREE_VEC, 20030726);
!   if (fns == NULL_TREE)
      {
        error ("non-template used as template");
        return error_mark_node;
      }
  
--- 3852,3863 ----
  
    if (fns == error_mark_node || arglist == error_mark_node)
      return error_mark_node;
  
    my_friendly_assert (!arglist || TREE_CODE (arglist) == TREE_VEC, 20030726);
!   if (fns == NULL_TREE 
!       || TREE_CODE (fns) == FUNCTION_DECL)
      {
        error ("non-template used as template");
        return error_mark_node;
      }
  
Index: testsuite/g++.dg/template/crash9.C
===================================================================
RCS file: testsuite/g++.dg/template/crash9.C
diff -N testsuite/g++.dg/template/crash9.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/crash9.C	5 Sep 2003 18:00:29 -0000
***************
*** 0 ****
--- 1,12 ----
+ struct A { };
+ struct B { };
+ 
+ A f(const B & b) {
+   return A();
+ }
+ 
+ template<>
+ B f(const A & a) { // { dg-error "" }
+   return B();
+ }
+ 
Index: testsuite/g++.dg/expr/static_cast4.C
===================================================================
RCS file: testsuite/g++.dg/expr/static_cast4.C
diff -N testsuite/g++.dg/expr/static_cast4.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/expr/static_cast4.C	5 Sep 2003 18:02:26 -0000
***************
*** 0 ****
--- 1,11 ----
+ class C { 
+ public: 
+     explicit C(int) {} 
+ }; 
+  
+ int main() 
+ { 
+     int i = 0; 
+     static_cast<C>(i); 
+     return 0; 
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]