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]

C++ PATCH: PRs 14324, 14260, 14337


This patch fixes three more C++ regressions in 3.4:

* 14324, which came from giving 'extern "C" linkage' to entities in
  function scope (!).

* 14260, which came from the parser not recognizing template-ids as
  constructor-declarators.  (That's a rare, but valid, usage.)

* 14337, which came from the two-phase name-lookup implementation in
  3.4.  By implementing that, along with the correct dependency-handling
  stuff, we tickled this problem.

  I fixed this by eliminating a call to tsubst_copy: all calls to
  tsubst_copy and either wrong or wasteful at this point, but
  disentangling things enough to completely eliminate the function
  will be something for 3.5.

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

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

2004-03-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14324
	* lex.c (retrofit_lang_decl): Treat entities with no linkage as
	having C++ linkage for name-mangling purposes.

	PR c++/14260
	* parser.c (cp_parser_direct_declarator): Recognize constructor
	declarators that use a template-id to name the class being
	constructed.

	PR c++/14337
	* pt.c (tsubst_qualified_id): Handle dependent qualifying scopes.
	(tsubst_expr): Do not call tsubst_copy, even when
	processing_template_decl.	

2004-03-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14324
	* g++.dg/abi/mangle21.C: New test.

	PR c++/14260
	* g++.dg/parse/constructor2.C: New test.

	PR c++/14337
	* g++.dg/template/sfinae1.C: New test.

Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.323.2.1
diff -c -5 -p -r1.323.2.1 lex.c
*** cp/lex.c	5 Feb 2004 22:01:38 -0000	1.323.2.1
--- cp/lex.c	1 Mar 2004 20:34:21 -0000
*************** retrofit_lang_decl (tree t)
*** 724,734 ****
    ld->decl_flags.u2sel = 0;
    if (ld->decl_flags.can_be_full)
      ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
  
    DECL_LANG_SPECIFIC (t) = ld;
!   if (current_lang_name == lang_name_cplusplus)
      SET_DECL_LANGUAGE (t, lang_cplusplus);
    else if (current_lang_name == lang_name_c)
      SET_DECL_LANGUAGE (t, lang_c);
    else if (current_lang_name == lang_name_java)
      SET_DECL_LANGUAGE (t, lang_java);
--- 724,735 ----
    ld->decl_flags.u2sel = 0;
    if (ld->decl_flags.can_be_full)
      ld->u.f.u3sel = TREE_CODE (t) == FUNCTION_DECL ? 1 : 0;
  
    DECL_LANG_SPECIFIC (t) = ld;
!   if (current_lang_name == lang_name_cplusplus
!       || decl_linkage (t) == lk_none)
      SET_DECL_LANGUAGE (t, lang_cplusplus);
    else if (current_lang_name == lang_name_c)
      SET_DECL_LANGUAGE (t, lang_c);
    else if (current_lang_name == lang_name_java)
      SET_DECL_LANGUAGE (t, lang_java);
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.157.2.16
diff -c -5 -p -r1.157.2.16 parser.c
*** cp/parser.c	1 Mar 2004 06:21:39 -0000	1.157.2.16
--- cp/parser.c	1 Mar 2004 20:34:21 -0000
*************** cp_parser_direct_declarator (cp_parser* 
*** 10537,10547 ****
  		}
  
  	      /* See if it names ctor, dtor or conv.  */
  	      if (TREE_CODE (unqualified_name) == BIT_NOT_EXPR
  		  || IDENTIFIER_TYPENAME_P (unqualified_name)
! 		  || constructor_name_p (unqualified_name, class_type))
  		*ctor_dtor_or_conv_p = -1;
  	    }
  
  	handle_declarator:;
  	  scope = get_scope_of_declarator (declarator);
--- 10537,10550 ----
  		}
  
  	      /* See if it names ctor, dtor or conv.  */
  	      if (TREE_CODE (unqualified_name) == BIT_NOT_EXPR
  		  || IDENTIFIER_TYPENAME_P (unqualified_name)
! 		  || constructor_name_p (unqualified_name, class_type)
! 		  || (TREE_CODE (unqualified_name) == TYPE_DECL
! 		      && same_type_p (TREE_TYPE (unqualified_name),
! 				      class_type)))
  		*ctor_dtor_or_conv_p = -1;
  	    }
  
  	handle_declarator:;
  	  scope = get_scope_of_declarator (declarator);
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.816.2.14
diff -c -5 -p -r1.816.2.14 pt.c
*** cp/pt.c	1 Mar 2004 06:21:39 -0000	1.816.2.14
--- cp/pt.c	1 Mar 2004 20:34:22 -0000
*************** tsubst_qualified_id (tree qualified_id, 
*** 7321,7331 ****
        expr = tsubst_copy (name, args, complain, in_decl);
      }
    else
      expr = name;
  
!   my_friendly_assert (!dependent_type_p (scope), 20030729);
    
    if (!BASELINK_P (name) && !DECL_P (expr))
      {
        expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0, false);
        if (TREE_CODE (TREE_CODE (expr) == TEMPLATE_DECL
--- 7321,7332 ----
        expr = tsubst_copy (name, args, complain, in_decl);
      }
    else
      expr = name;
  
!   if (dependent_type_p (scope))
!     return build_nt (SCOPE_REF, scope, expr);
    
    if (!BASELINK_P (name) && !DECL_P (expr))
      {
        expr = lookup_qualified_name (scope, expr, /*is_type_p=*/0, false);
        if (TREE_CODE (TREE_CODE (expr) == TEMPLATE_DECL
*************** tsubst_expr (tree t, tree args, tsubst_f
*** 7733,7745 ****
      = complain & (tf_stmt_expr_cmpd | tf_stmt_expr_body);
  
    complain ^= stmt_expr;
    if (t == NULL_TREE || t == error_mark_node)
      return t;
- 
-   if (processing_template_decl)
-     return tsubst_copy (t, args, complain, in_decl);
  
    if (!STATEMENT_CODE_P (TREE_CODE (t)))
      return tsubst_copy_and_build (t, args, complain, in_decl,
  				  /*function_p=*/false);
      
--- 7734,7743 ----
Index: testsuite/g++.dg/abi/mangle21.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle21.C
diff -N testsuite/g++.dg/abi/mangle21.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle21.C	1 Mar 2004 20:34:25 -0000
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/14324
+ // { dg-do assemble }
+ 
+ extern "C" {
+ 
+ void fun1(void)
+ {
+   do { static int xyz __attribute__((unused)) = 1; } while (0);
+   do { static int xyz __attribute__((unused)) = 2; } while (0);
+   do { static int xyz __attribute__((unused)) = 3; } while (0);
+ }
+ 
+ }
Index: testsuite/g++.dg/parse/constructor2.C
===================================================================
RCS file: testsuite/g++.dg/parse/constructor2.C
diff -N testsuite/g++.dg/parse/constructor2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/constructor2.C	1 Mar 2004 20:34:25 -0000
***************
*** 0 ****
--- 1,11 ----
+ // PR c++/14260
+ 
+ template <class TClass> 
+ class T 
+ { 
+ public: 
+   T(short,short f=0) {} 
+   T<TClass>(int f) {} 
+   T<TClass>(int f=0,const char* b=0) {} 
+ }; 
+ 
Index: testsuite/g++.dg/template/sfinae1.C
===================================================================
RCS file: testsuite/g++.dg/template/sfinae1.C
diff -N testsuite/g++.dg/template/sfinae1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/sfinae1.C	1 Mar 2004 20:34:25 -0000
***************
*** 0 ****
--- 1,21 ----
+ // PR c++/14337
+ 
+ template <bool> struct Constraint; 
+ template <>     struct Constraint<true> { typedef int Result; }; 
+  
+ template <typename T> 
+ struct IsInt      { static const bool value = false; }; 
+  
+ template <> 
+ struct IsInt<int> { static const bool value = true; }; 
+  
+ template <typename T> 
+ typename Constraint<IsInt<T>::value>::Result foo(T); 
+  
+ template <typename T> 
+ typename Constraint<!IsInt<T>::value>::Result foo(T); 
+  
+ template <typename> 
+ void bar() { 
+     foo(1); 
+ } 


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