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]

(C++) `main' mangling cleanup


Applied.  We were erroneously treating namespace-scope functions named main
like ::main.

1998-10-15  Jason Merrill  <jason@yorick.cygnus.com>

	* decl.c (grokfndecl): ::main and __builtin_* get C linkage.
	Do mangling here.
	(grokdeclarator): Instead of here.
	* friend.c (do_friend): Lose special handling of ::main and
	__builtin_*.

Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.231
diff -c -p -r1.231 decl.c
*** decl.c	1998/10/15 11:27:42	1.231
--- decl.c	1998/10/16 02:16:48
*************** grokfndecl (ctype, type, declarator, ori
*** 8016,8021 ****
--- 8016,8034 ----
    if (in_namespace)
      set_decl_namespace (decl, in_namespace);
  
+   /* `main' and builtins have implicit 'C' linkage.  */
+   if ((MAIN_NAME_P (declarator)
+        || (IDENTIFIER_LENGTH (declarator) > 10
+ 	   && IDENTIFIER_POINTER (declarator)[0] == '_'
+ 	   && IDENTIFIER_POINTER (declarator)[1] == '_'
+ 	   && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
+       && current_lang_name == lang_name_cplusplus
+       /* context == 0 could mean global scope or not set yet; either is fine
+ 	 for us here, as we check current_namespace.  */
+       && DECL_CONTEXT (decl) == NULL_TREE
+       && current_namespace == global_namespace)
+     DECL_LANGUAGE (decl) = lang_c;
+ 
    /* Should probably propagate const out from type to decl I bet (mrs).  */
    if (staticp)
      {
*************** grokfndecl (ctype, type, declarator, ori
*** 8026,8032 ****
    if (ctype)
      DECL_CLASS_CONTEXT (decl) = ctype;
  
!   if (ctype == NULL_TREE && MAIN_NAME_P (declarator))
      {
        if (inlinep)
  	error ("cannot declare `main' to be inline");
--- 8039,8045 ----
    if (ctype)
      DECL_CLASS_CONTEXT (decl) = ctype;
  
!   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
      {
        if (inlinep)
  	error ("cannot declare `main' to be inline");
*************** grokfndecl (ctype, type, declarator, ori
*** 8123,8128 ****
--- 8136,8147 ----
  	}
      }
  
+   /* Plain overloading: will not be grok'd by grokclassfn.  */
+   if (! ctype && ! processing_template_decl
+       && DECL_LANGUAGE (decl) != lang_c
+       && (! DECL_USE_TEMPLATE (decl) || name_mangling_version < 1))
+     set_mangled_name_for_decl (decl);
+ 
    /* Caller will do the rest of this.  */
    if (check < 0)
      return decl;
*************** grokdeclarator (declarator, declspecs, d
*** 10625,10642 ****
  		error ("virtual non-class function `%s'", name);
  		virtualp = 0;
  	      }
- 
- 	    if (current_lang_name == lang_name_cplusplus
- 		&& ! processing_template_decl
- 		&& ! MAIN_NAME_P (original_name)
- 		&& ! (IDENTIFIER_LENGTH (original_name) > 10
- 		      && IDENTIFIER_POINTER (original_name)[0] == '_'
- 		      && IDENTIFIER_POINTER (original_name)[1] == '_'
- 		      && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
- 	      /* Plain overloading: will not be grok'd by grokclassfn.  */
- 	      if (name_mangling_version < 1 
- 		  || TREE_CODE (declarator) != TEMPLATE_ID_EXPR)
- 		declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
  	  }
  	else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  	  type = build_cplus_method_type (ctype, TREE_TYPE (type),
--- 10644,10649 ----
*************** grokdeclarator (declarator, declspecs, d
*** 10660,10670 ****
  	if (decl == error_mark_node)
  	  return error_mark_node;
  
- 	if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c
- 	    && (! DECL_USE_TEMPLATE (decl) ||
- 		name_mangling_version < 1)) 
- 	  DECL_ASSEMBLER_NAME (decl) = declarator;
- 	
  	if (staticp == 1)
  	  {
  	    int illegal_static = 0;
--- 10667,10672 ----
Index: friend.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/friend.c,v
retrieving revision 1.32
diff -c -p -r1.32 friend.c
*** friend.c	1998/10/06 14:19:57	1.32
--- friend.c	1998/10/16 02:16:48
*************** do_friend (ctype, declarator, decl, parm
*** 405,424 ****
  	  decl = void_type_node;
  	}
      }
-   else if (TREE_CODE (decl) == FUNCTION_DECL
- 	   && (MAIN_NAME_P (declarator)
- 	       || (IDENTIFIER_LENGTH (declarator) > 10
- 		   && IDENTIFIER_POINTER (declarator)[0] == '_'
- 		   && IDENTIFIER_POINTER (declarator)[1] == '_'
- 		   && strncmp (IDENTIFIER_POINTER (declarator)+2,
- 			       "builtin_", 8) == 0)))
-     {
-       /* raw "main", and builtin functions never gets overloaded,
- 	 but they can become friends.  */
-       add_friend (current_class_type, decl);
-       DECL_FRIEND_P (decl) = 1;
-       decl = void_type_node;
-     }
    /* A global friend.
       @@ or possibly a friend from a base class ?!?  */
    else if (TREE_CODE (decl) == FUNCTION_DECL)
--- 405,410 ----


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