[PATCH] Fix location of typeid() (PR c++/80014)

Jason Merrill jason@redhat.com
Wed Mar 15 20:35:00 GMT 2017


On Tue, Mar 14, 2017 at 9:05 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> OK for trunk now, or should this wait until stage 1?

Stage 1.

> +       cp_token *close_paren = cp_parser_require (parser, CPP_CLOSE_PAREN,
> +                                                  RT_CLOSE_PAREN);
> +       location_t end_loc = close_paren ?
> +         close_paren->location : UNKNOWN_LOCATION;
>         /* If all went well, simply lookup the type-id.  */
>         if (cp_parser_parse_definitely (parser))
>           postfix_expression = get_typeid (type, tf_warning_or_error);
> @@ -6527,13 +6530,23 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
>             /* Compute its typeid.  */
>             postfix_expression = build_typeid (expression, tf_warning_or_error);
>             /* Look for the `)' token.  */
> -           cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
> +           close_paren
> +             = cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
> +           end_loc = close_paren ? close_paren->location : UNKNOWN_LOCATION;

In both cases you're setting end_loc from close_paren, so how about
only computing it once, closer to where it's used?

Jason



More information about the Gcc-patches mailing list