[PATCH] libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]

Marek Polacek polacek@redhat.com
Wed Nov 17 15:59:37 GMT 2021


On Wed, Nov 17, 2021 at 10:22:32AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> Normal preprocessing, -fdirectives-only preprocessing before the Nathan's
> rewrite, and all other compilers I've tried on godbolt treat even \*/
> as end of a block comment, but the new -fdirectives-only handling doesn't.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK for trunk and 11, thanks.
 
> 2021-11-17  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR preprocessor/103130
> 	* lex.c (cpp_directive_only_process): Treat even \*/ as end of block
> 	comment.
> 
> 	* c-c++-common/cpp/dir-only-9.c: New test.
> 
> --- libcpp/lex.c.jj	2021-11-01 14:37:06.706853026 +0100
> +++ libcpp/lex.c	2021-11-16 16:54:04.022644499 +0100
> @@ -4493,7 +4493,7 @@ cpp_directive_only_process (cpp_reader *
>  			break;
>  
>  		      case '*':
> -			if (pos > peek && !esc)
> +			if (pos > peek)
>  			  star = is_block;
>  			esc = false;
>  			break;
> --- gcc/testsuite/c-c++-common/cpp/dir-only-9.c.jj	2021-11-16 16:56:57.121217975 +0100
> +++ gcc/testsuite/c-c++-common/cpp/dir-only-9.c	2021-11-16 16:56:14.524815094 +0100
> @@ -0,0 +1,13 @@
> +/* PR preprocessor/103130 */
> +/* { dg-do preprocess } */
> +/* { dg-options -fdirectives-only } */
> +
> +/*\
> + * this is a comment
> +\*/
> +
> +int
> +main ()
> +{
> +  return 0;
> +}
> 
> 	Jakub
> 

Marek



More information about the Gcc-patches mailing list