This is the mail archive of the gcc-bugs@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]

[Bug c++/13305] New: Parser error with 'class __attribute__((dllimport)) Foo;' type specifier


The following code fails on 3.4 but compiled without error on
3.3.x, 3.2.x and 3.1.x (and IIRC, earlier g++)

=====================================
// forward_type_spec.C

// This parses without error.
struct  Foo __attribute__((dllimport));

// This fails.
struct  __attribute__((dllimport)) Faz;


struct Bar 
{
  void  useFoo (Foo&);
  void  useFaz (Faz&);
};
=======================================


> D:\develop\bugs>g++ -c forward_type_spec.C 
outputs:

forward_type_spec.C:5: error: expected identifier
forward_type_spec.C:5: error: ISO C++ forbids declaration of `Faz' with no type
forward_type_spec.C:11: error: variable or field `useFaz' declared void
forward_type_spec.C:11: error: expected function-definition


The problem seems to be in parser.c (cp_parser_elaborated_type_specifier)
The following (naive) patch fixes, and allows building of projects
(eg STLPort) which use this syntax for forward declarations.


2003-12-04  Danny Smith  <dannysmith@users,sourceforge.net>

	* parser,c (cp_parser_elaborated_type_specifier): Allow
	'class-key attribute-list [opt] identifier' syntax on
	windows targets.


Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.122
diff -c -3 -p -r1.122 parser.c
*** parser.c	21 Nov 2003 11:36:58 -0000	1.122
--- parser.c	4 Dec 2003 19:50:06 -0000
*************** cp_parser_elaborated_type_specifier (cp_
*** 8506,8511 ****
--- 8506,8512 ----
    enum tag_types tag_type;
    tree identifier;
    tree type = NULL_TREE;
+   tree attributes = NULL_TREE;
  
    /* See if we're looking at the `enum' keyword.  */
    if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ENUM))
*************** cp_parser_elaborated_type_specifier (cp_
*** 8533,8538 ****
--- 8534,8549 ----
        tag_type = cp_parser_class_key (parser);
        if (tag_type == none_type)
  	return error_mark_node;
+ #ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+       /* Windows targets allow forward declarations or redeclarations
+          specified as 'class __attribute__ ((dllimport)) identifier'.  */
+        /* FIXME. Should this be enabled on other targets to consume
+ 	  and warn about attributes here?  */
+         if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ATTRIBUTE))
+ 	{
+           attributes = cp_parser_attributes_opt (parser);
+ 	}
+ #endif
      }
  
    /* Look for the `::' operator.  */
*************** cp_parser_elaborated_type_specifier (cp_
*** 8699,8705 ****
  	     declaration context.  */
  
  	  type = xref_tag (tag_type, identifier, 
! 			   /*attributes=*/NULL_TREE,
  			   (is_friend 
  			    || !is_declaration
  			    || cp_lexer_next_token_is_not (parser->lexer, 
--- 8710,8716 ----
  	     declaration context.  */
  
  	  type = xref_tag (tag_type, identifier, 
! 			   attributes,
  			   (is_friend 
  			    || !is_declaration
  			    || cp_lexer_next_token_is_not (parser->lexer,

-- 
           Summary: Parser error with 'class __attribute__((dllimport))
                    Foo;'  type specifier
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dannysmith at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,mark at codesourcery dot
                    com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13305


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