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++ PATH: Fix PR 17595


PR 17595 was a complaint about the fact that the G++ no longer allows
#pragmas in arbitrary locations, and does not issue very graceful
messages about that fact.  There's no reason to allow #pragmas in
arbitrary locations, but we can be a bit more helpful with the
messages.  We could try to do even better, with respect to error
messages, but we now give a good first error message.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.

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

2004-12-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17595
	* parser.c (cp_parser_error): Issue better messages about
	#pragma in locations where it is not permitted.

2004-12-23  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17595
	* g++.dg/parse/pragma2.C: New test.

Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.297
diff -c -5 -p -r1.297 parser.c
*** parser.c	22 Dec 2004 03:34:53 -0000	1.297
--- parser.c	23 Dec 2004 22:06:44 -0000
*************** cp_parser_error (cp_parser* parser, cons
*** 1782,1791 ****
--- 1782,1797 ----
      {
        cp_token *token = cp_lexer_peek_token (parser->lexer);
        /* This diagnostic makes more sense if it is tagged to the line
  	 of the token we just peeked at.  */
        cp_lexer_set_source_position_from_token (token);
+       if (token->type == CPP_PRAGMA)
+ 	{
+ 	  error ("%<#pragma%> is not allowed here"); 
+ 	  cp_lexer_purge_token (parser->lexer);
+ 	  return;
+ 	}
        c_parse_error (message,
  		     /* Because c_parser_error does not understand
  			CPP_KEYWORD, keywords are treated like
  			identifiers.  */
  		     (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
Index: testsuite/g++.dg/parse/pragma2.C
===================================================================
RCS file: testsuite/g++.dg/parse/pragma2.C
diff -N testsuite/g++.dg/parse/pragma2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/pragma2.C	23 Dec 2004 22:18:50 -0000
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/17595
+ 
+ // Ideally, the #pragma error would come one line further down, but it
+ // does not.
+ int f(int x, // { dg-error "not allowed here" }
+ #pragma interface 
+       // The parser gets confused and issues an error on the next line.
+       int y); // { dg-bogus "" "" { xfail *-*-* } } 


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