[PATCH][CilkPlus] Allow parenthesized initialization in for-loops

Jason Merrill jason@redhat.com
Thu May 19 14:36:00 GMT 2016


On 05/10/2016 03:28 PM, Ilya Verbin wrote:
>>> What about (some_class i { 0 }; some_class < ...; some_class++)
>>> and similar syntax?
>>
>> It's allowed, thanks, I missed this in the initial patch.
>>
>>> The testsuite coverage is insufficient (nothing e.g.
>>> tests templates or #pragma simd).
>>
>> Patch is updated.  Is it sufficient now?

> -		  if (!CLASS_TYPE_P (TREE_TYPE (decl))
> -		      && !type_dependent_expression_p (decl))
> +		  if (!is_class && !type_dependent_expression_p (decl))
>  		    goto non_class;
>  		}
> -		
> +
>  	      cp_finish_decl (decl, init, !is_non_constant_init,
>  			      asm_specification,
>  			      LOOKUP_ONLYCONVERTING);
>  	      orig_init = init;
> -	      if (CLASS_TYPE_P (TREE_TYPE (decl)))
> +	      if (is_class)

This change is wrong; do_auto_deduction will have changed TREE_TYPE 
(decl), so it could be a class now.

> +	  else if (is_cilk && next_is_op_paren)
> +	    {
> +	      cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
> +	      init = cp_parser_assignment_expression (parser);
> +	      cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
> +	      goto non_class;
> +	    }
> +	  else if (is_cilk && next_is_eq)
> +	    {
> +	      bool braced = false;
> +	      cp_parser_require (parser, CPP_EQ, RT_EQ);
> +	      if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
> +		{
> +		  braced = true;
> +		  cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
> +		}
> +	      init = cp_parser_assignment_expression (parser);
> +	      if (braced)
> +		cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
> +	      goto non_class;
> +	    }
> +	  else if (is_cilk && next_is_op_brace)
> +	    {
> +	      cp_lexer_set_source_position (parser->lexer);
> +	      maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
> +	      cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
> +	      init = cp_parser_assignment_expression (parser);
> +	      cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
> +	      goto non_class;
> +	    }

Why not use cp_parser_initializer for scalars?

Jason



More information about the Gcc-patches mailing list