C++ PATCH: PR 17042, 14667, 17852

Mark Mitchell mark@codesourcery.com
Fri Oct 15 21:33:00 GMT 2004


This patch fixes three 4.0 regressions:

PR 17042: A case where the user explicitly declared __dso_handle.  We
were failing to correctly merge built-in declarations with user
declarations.

PR 14667: The fancy code for trying to detect incorrect declarations
(where something that looks like a type does not actually name a type)
was incorrectly being called in situations that were not erroneous.
It was then silently consuming tokens, resulting in us silently
accepting invalid code.

PR 17852: #pragma was not being handled inside a class-specifier.

Tested on i686-pc-linux-gnu, applied on the mainline

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

2004-10-15  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17042
	* decl.c (declare_global_var): Use the return value from pushdecl.

	PR c++/14667
	* parser.c (cp_parser_simple_declaration): Do not diagnose invalid
	type names if we have already found a valid type.
	(cp_parser_member_declaration): Likewise.
	
	PR c++/17852
	* parser.c (cp_parser_member_specification_opt): Handle
	CPP_PRAGMA.

2004-10-15  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17042
	* g++.dg/init/dso_handle1.C: New test.

	PR c++/14667
	* g++.dg/parse/typedef6.C: New test.

	PR c++/17852
	* g++.dg/parse/pragma1.C: New test.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1314
diff -c -5 -p -r1.1314 decl.c
*** cp/decl.c	15 Oct 2004 04:17:42 -0000	1.1314
--- cp/decl.c	15 Oct 2004 20:32:17 -0000
*************** declare_global_var (tree name, tree type
*** 5027,5037 ****
    push_to_top_level ();
    decl = build_decl (VAR_DECL, name, type);
    TREE_PUBLIC (decl) = 1;
    DECL_EXTERNAL (decl) = 1;
    DECL_ARTIFICIAL (decl) = 1;
!   pushdecl (decl);
    cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
    pop_from_top_level ();
  
    return decl;
  }
--- 5027,5041 ----
    push_to_top_level ();
    decl = build_decl (VAR_DECL, name, type);
    TREE_PUBLIC (decl) = 1;
    DECL_EXTERNAL (decl) = 1;
    DECL_ARTIFICIAL (decl) = 1;
!   /* If the user has explicitly declared this variable (perhaps
!      because the code we are compiling is part of a low-level runtime
!      library), then it is possible that our declaration will be merged
!      with theirs by pushdecl.  */
!   decl = pushdecl (decl);
    cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
    pop_from_top_level ();
  
    return decl;
  }
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.263
diff -c -5 -p -r1.263 parser.c
*** cp/parser.c	12 Oct 2004 01:52:11 -0000	1.263
--- cp/parser.c	15 Oct 2004 20:32:18 -0000
*************** cp_parser_simple_declaration (cp_parser*
*** 6951,6961 ****
       erroneous. The usual cause of this situation is code like:
  
         T t;
  
       where "T" should name a type -- but does not.  */
!   if (cp_parser_parse_and_diagnose_invalid_type_name (parser))
      {
        /* If parsing tentatively, we should commit; we really are
  	 looking at a declaration.  */
        cp_parser_commit_to_tentative_parse (parser);
        /* Give up.  */
--- 6951,6962 ----
       erroneous. The usual cause of this situation is code like:
  
         T t;
  
       where "T" should name a type -- but does not.  */
!   if (!decl_specifiers.type
!       && cp_parser_parse_and_diagnose_invalid_type_name (parser))
      {
        /* If parsing tentatively, we should commit; we really are
  	 looking at a declaration.  */
        cp_parser_commit_to_tentative_parse (parser);
        /* Give up.  */
*************** cp_parser_member_specification_opt (cp_p
*** 12878,12887 ****
--- 12879,12895 ----
  	  /* Look for the `:'.  */
  	  cp_parser_require (parser, CPP_COLON, "`:'");
  	  break;
  
  	default:
+ 	  /* Accept #pragmas at class scope.  */
+ 	  if (token->type == CPP_PRAGMA)
+ 	    {
+ 	      cp_lexer_handle_pragma (parser->lexer);
+ 	      break;
+ 	    }
+ 
  	  /* Otherwise, the next construction must be a
  	     member-declaration.  */
  	  cp_parser_member_declaration (parser);
  	}
      }
*************** cp_parser_member_declaration (cp_parser*
*** 12961,12971 ****
  				&decl_specifiers,
  				&declares_class_or_enum);
    prefix_attributes = decl_specifiers.attributes;
    decl_specifiers.attributes = NULL_TREE;
    /* Check for an invalid type-name.  */
!   if (cp_parser_parse_and_diagnose_invalid_type_name (parser))
      return;
    /* If there is no declarator, then the decl-specifier-seq should
       specify a type.  */
    if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
      {
--- 12969,12980 ----
  				&decl_specifiers,
  				&declares_class_or_enum);
    prefix_attributes = decl_specifiers.attributes;
    decl_specifiers.attributes = NULL_TREE;
    /* Check for an invalid type-name.  */
!   if (!decl_specifiers.type
!       && cp_parser_parse_and_diagnose_invalid_type_name (parser))
      return;
    /* If there is no declarator, then the decl-specifier-seq should
       specify a type.  */
    if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
      {
Index: testsuite/g++.dg/init/dso_handle1.C
===================================================================
RCS file: testsuite/g++.dg/init/dso_handle1.C
diff -N testsuite/g++.dg/init/dso_handle1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/dso_handle1.C	15 Oct 2004 20:33:00 -0000
***************
*** 0 ****
--- 1,10 ----
+ // PR c++/17042
+ // { dg-do assemble }
+ // { dg-options "-fuse-cxa-atexit" }
+ 
+ struct A
+ {  A();  ~A(); };
+ A a;
+ extern "C" { void* __dso_handle __attribute__ ((__weak__)); }
+ void f()
+ {  __dso_handle = 0; }
Index: testsuite/g++.dg/parse/typedef6.C
===================================================================
RCS file: testsuite/g++.dg/parse/typedef6.C
diff -N testsuite/g++.dg/parse/typedef6.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/typedef6.C	15 Oct 2004 20:33:00 -0000
***************
*** 0 ****
--- 1,6 ----
+ // PR c++/14667
+ 
+ template<class T>
+ class Class1;
+ 
+ class Class2 {} typedef Class1<Class2> Type1; // { dg-error "" }
Index: testsuite/g++.dg/parse/pragma1.C
===================================================================
RCS file: testsuite/g++.dg/parse/pragma1.C
diff -N testsuite/g++.dg/parse/pragma1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/pragma1.C	15 Oct 2004 20:33:00 -0000
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/17852
+ 
+ class T {
+ #pragma X
+   struct S {
+   };
+ #pragma Y
+ };



  



More information about the Gcc-patches mailing list