[C++ patch] report better diagnostic for static following '[' in parameter declaration

Marek Polacek polacek@redhat.com
Thu Jan 28 23:33:00 GMT 2016


On Fri, Jan 29, 2016 at 04:46:56AM +0530, Prathamesh Kulkarni wrote:
> @@ -19016,10 +19017,22 @@ cp_parser_direct_declarator (cp_parser* parser,
>  	  cp_lexer_consume_token (parser->lexer);
>  	  /* Peek at the next token.  */
>  	  token = cp_lexer_peek_token (parser->lexer);
> +
> +	  /* If static keyword immediately follows [, report error.  */
> +	  if (cp_lexer_next_token_is_keyword (parser->lexer, RID_STATIC)
> +	      && current_binding_level->kind == sk_function_parms)
> +	    {
> +	      error_at (token->location,
> +			"static array size is a C99 feature,"
> +			"not permitted in C++");
> +	      bounds = error_mark_node;
> +	    }
> +

I think this isn't sufficient as-is; if we're changing the diagnostics here,
we should also handle e.g. void f(int a[const 10]); where clang++ says
g.C:1:13: error: qualifier in array size is a C99 feature, not permitted in C++

And also e.g.
void f(int a[const static 10]);
void f(int a[static const 10]);
and similar.

	Marek



More information about the Gcc-patches mailing list