(C++) patch for handling attributes on static data members

Mumit Khan khan@xraylith.wisc.EDU
Tue Jul 20 17:11:00 GMT 1999


The enclosed patch fixes the following bug on x86:

  struct foo {
    static __attribute__((stdcall)) bool (*fp) (int);
  };
  bool __attribute__((stdcall)) (*foo::fp) (int);

See:
   Linkname: (c++) 2.95 regression for attributes on static memfn
   URL: http://egcs.cygnus.com/ml/gcc-bugs/1999-07/msg00628.html

It used to work during egcs-1.1.x days when i386_comp_type_attributes
simply ignored the attributes and return 1 no matter what; when it
was fixed to actually check for conflicting attributes, the C++ front
broke because it was calling duplicate_decls for static data members
*before* calling cplus_decl_attributes. 

No regression for release branch on i686-pc-linux-gnu, i586-pc-cygwin32.

Tue Jul 20 17:41:22 1999  Mumit Khan  <khan@xraylith.wisc.edu>

	* decl.c (start_decl): Set attributes before duplicate_decls call.

Index: cp/decl.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/gcc-2.95/gcc/cp/decl.c,v
retrieving revision 1.5
diff -u -3 -p -r1.5 decl.c
--- decl.c	1999/07/04 18:23:20	1.5
+++ decl.c	1999/07/20 22:00:42
@@ -7339,6 +7339,13 @@ start_decl (declarator, declspecs, initi
       DECL_INITIAL (decl) = error_mark_node;
     }
 
+#ifdef SET_DEFAULT_DECL_ATTRIBUTES
+  SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes);
+#endif
+  
+  /* Set attributes here so if duplicate decl, will have proper attributes.  */
+  cplus_decl_attributes (decl, attributes, prefix_attributes);
+
   if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE)
     {
       push_nested_class (context, 2);
@@ -7395,13 +7402,6 @@ start_decl (declarator, declspecs, initi
 	cp_pedwarn ("declaration of `%#D' outside of class is not definition",
 		    decl);
     }
-
-#ifdef SET_DEFAULT_DECL_ATTRIBUTES
-  SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes);
-#endif
-  
-  /* Set attributes here so if duplicate decl, will have proper attributes.  */
-  cplus_decl_attributes (decl, attributes, prefix_attributes);
 
   /* Add this decl to the current binding level, but not if it
      comes from another scope, e.g. a static member variable.

Regards,
Mumit



More information about the Gcc-patches mailing list