diff options
Diffstat (limited to 'gcc/c-parser.c')
-rw-r--r-- | gcc/c-parser.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 033c835..beda817 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -820,12 +820,14 @@ disable_extension_diagnostics (void) | (warn_pointer_arith << 1) | (warn_traditional << 2) | (flag_iso << 3) - | (warn_long_long << 4)); + | (warn_long_long << 4) + | (warn_cxx_compat << 5)); cpp_opts->pedantic = pedantic = 0; warn_pointer_arith = 0; cpp_opts->warn_traditional = warn_traditional = 0; flag_iso = 0; cpp_opts->warn_long_long = warn_long_long = 0; + warn_cxx_compat = 0; return ret; } @@ -840,6 +842,7 @@ restore_extension_diagnostics (int flags) cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1; flag_iso = (flags >> 3) & 1; cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1; + warn_cxx_compat = (flags >> 5) & 1; } /* Possibly kinds of declarator to parse. */ @@ -910,7 +913,8 @@ static struct c_expr c_parser_sizeof_expression (c_parser *); static struct c_expr c_parser_alignof_expression (c_parser *); static struct c_expr c_parser_postfix_expression (c_parser *); static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, - struct c_type_name *); + struct c_type_name *, + location_t); static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, struct c_expr); static struct c_expr c_parser_expression (c_parser *); @@ -1620,8 +1624,10 @@ c_parser_enum_specifier (c_parser *parser) struct c_typespec ret; tree attrs; tree ident = NULL_TREE; + location_t enum_loc; location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); + enum_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); /* Set the location in case we create a decl now. */ @@ -1630,13 +1636,14 @@ c_parser_enum_specifier (c_parser *parser) { ident = c_parser_peek_token (parser)->value; ident_loc = c_parser_peek_token (parser)->location; + enum_loc = ident_loc; c_parser_consume_token (parser); } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { /* Parse an enum definition. */ struct c_enum_contents the_enum; - tree type = start_enum (&the_enum, ident); + tree type = start_enum (&the_enum, ident, enum_loc); tree postfix_attrs; /* We chain the enumerators in reverse order, then put them in forward order at the end. */ @@ -1715,7 +1722,7 @@ c_parser_enum_specifier (c_parser *parser) ret.expr_const_operands = true; return ret; } - ret = parser_xref_tag (ENUMERAL_TYPE, ident); + ret = parser_xref_tag (ENUMERAL_TYPE, ident, ident_loc); /* In ISO C, enumerated types can be referred to only if already defined. */ if (pedantic && !COMPLETE_TYPE_P (ret.spec)) @@ -1772,6 +1779,8 @@ c_parser_struct_or_union_specifier (c_parser *parser) struct c_typespec ret; tree attrs; tree ident = NULL_TREE; + location_t struct_loc; + location_t ident_loc = UNKNOWN_LOCATION; enum tree_code code; switch (c_parser_peek_token (parser)->keyword) { @@ -1784,6 +1793,7 @@ c_parser_struct_or_union_specifier (c_parser *parser) default: gcc_unreachable (); } + struct_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); /* Set the location in case we create a decl now. */ @@ -1791,13 +1801,18 @@ c_parser_struct_or_union_specifier (c_parser *parser) if (c_parser_next_token_is (parser, CPP_NAME)) { ident = c_parser_peek_token (parser)->value; + ident_loc = c_parser_peek_token (parser)->location; + struct_loc = ident_loc; c_parser_consume_token (parser); } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { /* Parse a struct or union definition. Start the scope of the tag before parsing components. */ - tree type = start_struct (code, ident); + bool in_struct; + VEC(tree,heap) *struct_types; + tree type = start_struct (code, ident, &in_struct, &struct_types, + struct_loc); tree postfix_attrs; /* We chain the components in reverse order, then put them in forward order at the end. Each struct-declaration may @@ -1887,7 +1902,8 @@ c_parser_struct_or_union_specifier (c_parser *parser) } postfix_attrs = c_parser_attributes (parser); ret.spec = finish_struct (type, nreverse (contents), - chainon (attrs, postfix_attrs)); + chainon (attrs, postfix_attrs), + in_struct, struct_types); ret.kind = ctsk_tagdef; ret.expr = NULL_TREE; ret.expr_const_operands = true; @@ -1902,7 +1918,7 @@ c_parser_struct_or_union_specifier (c_parser *parser) ret.expr_const_operands = true; return ret; } - ret = parser_xref_tag (code, ident); + ret = parser_xref_tag (code, ident, ident_loc); return ret; } @@ -4843,10 +4859,12 @@ c_parser_cast_expression (c_parser *parser, struct c_expr *after) if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) { + location_t loc; struct c_type_name *type_name; struct c_expr ret; struct c_expr expr; c_parser_consume_token (parser); + loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) @@ -4861,11 +4879,11 @@ c_parser_cast_expression (c_parser *parser, struct c_expr *after) used_types_insert (type_name->specs->type); if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) - return c_parser_postfix_expression_after_paren_type (parser, - type_name); + return c_parser_postfix_expression_after_paren_type (parser, type_name, + loc); expr = c_parser_cast_expression (parser, NULL); expr = default_function_array_conversion (expr); - ret.value = c_cast_expr (type_name, expr.value); + ret.value = c_cast_expr (type_name, expr.value, loc); ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; @@ -5036,7 +5054,8 @@ c_parser_sizeof_expression (c_parser *parser) if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { expr = c_parser_postfix_expression_after_paren_type (parser, - type_name); + type_name, + expr_loc); goto sizeof_expr; } /* sizeof ( type-name ). */ @@ -5073,9 +5092,11 @@ c_parser_alignof_expression (c_parser *parser) { /* Either __alignof__ ( type-name ) or __alignof__ unary-expression starting with a compound literal. */ + location_t loc; struct c_type_name *type_name; struct c_expr ret; c_parser_consume_token (parser); + loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) @@ -5091,7 +5112,8 @@ c_parser_alignof_expression (c_parser *parser) if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { expr = c_parser_postfix_expression_after_paren_type (parser, - type_name); + type_name, + loc); goto alignof_expr; } /* alignof ( type-name ). */ @@ -5262,8 +5284,10 @@ c_parser_postfix_expression (c_parser *parser) than going directly to c_parser_postfix_expression_after_paren_type from elsewhere? */ + location_t loc; struct c_type_name *type_name; c_parser_consume_token (parser); + loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); @@ -5273,7 +5297,8 @@ c_parser_postfix_expression (c_parser *parser) } else expr = c_parser_postfix_expression_after_paren_type (parser, - type_name); + type_name, + loc); } else { @@ -5591,11 +5616,14 @@ c_parser_postfix_expression (c_parser *parser) possible to tell until after the type name whether a cast expression has a cast or a compound literal, or whether the operand of sizeof is a parenthesized type name or starts with a compound - literal. */ + literal. TYPE_LOC is the location where TYPE_NAME starts--the + location of the first token after the parentheses around the type + name. */ static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *parser, - struct c_type_name *type_name) + struct c_type_name *type_name, + location_t type_loc) { tree type; struct c_expr init; @@ -5604,12 +5632,13 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, location_t start_loc; tree type_expr = NULL_TREE; bool type_expr_const = true; + check_compound_literal_type (type_name, type_loc); start_init (NULL_TREE, NULL, 0); type = groktypename (type_name, &type_expr, &type_expr_const); start_loc = c_parser_peek_token (parser)->location; if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) { - error_at (start_loc, "compound literal has variable size"); + error_at (type_loc, "compound literal has variable size"); type = error_mark_node; } init = c_parser_braced_init (parser, type, false); |