aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-11-22 14:09:25 -0500
committerMarek Polacek <polacek@redhat.com>2021-11-24 00:22:10 -0500
commitd71d019f63ed5d3fdb34579023bafa4dcf323f2c (patch)
tree21384cd37c5ec8783cd0e7463c81c87f7f12c9eb /gcc/cp/parser.c
parent9bf69a8558638ce0cdd69e83a68776deb9b8e053 (diff)
downloadgcc-d71d019f63ed5d3fdb34579023bafa4dcf323f2c.zip
gcc-d71d019f63ed5d3fdb34579023bafa4dcf323f2c.tar.gz
gcc-d71d019f63ed5d3fdb34579023bafa4dcf323f2c.tar.bz2
c++: Fix missing NSDMI diagnostic in C++98 [PR103347]
Here the problem is that we aren't detecting a NSDMI in C++98: struct A { void *x = NULL; }; because maybe_warn_cpp0x uses input_location and that happens to point to NULL which comes from a system header. Jakub suggested changing the location to the '=', thereby avoiding the system header problem. To that end, I've added a new location_t member into cp_declarator. This member is used when this declarator is part of an init-declarator. The rest of the changes is obvious. I've also taken the liberty of adding loc_or_input_loc, since I want to avoid checking for UNKNOWN_LOCATION. PR c++/103347 gcc/cp/ChangeLog: * cp-tree.h (struct cp_declarator): Add a location_t member. (maybe_warn_cpp0x): Add a location_t parameter with a default argument. (loc_or_input_loc): New. * decl.c (grokdeclarator): Use loc_or_input_loc. Pass init_loc down to maybe_warn_cpp0x. * error.c (maybe_warn_cpp0x): Add a location_t parameter. Use it. * parser.c (make_declarator): Initialize init_loc. (cp_parser_member_declaration): Set init_loc. (cp_parser_condition): Likewise. (cp_parser_init_declarator): Likewise. (cp_parser_parameter_declaration): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-warn1.C: New test. * g++.dg/cpp0x/nsdmi-warn1.h: New file.
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index e2b5d68..7a6a302 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1542,6 +1542,7 @@ make_declarator (cp_declarator_kind kind)
declarator->declarator = NULL;
declarator->parameter_pack_p = false;
declarator->id_loc = UNKNOWN_LOCATION;
+ declarator->init_loc = UNKNOWN_LOCATION;
return declarator;
}
@@ -13286,6 +13287,7 @@ cp_parser_condition (cp_parser* parser)
attributes, prefix_attributes,
&pushed_scope);
+ declarator->init_loc = cp_lexer_peek_token (parser->lexer)->location;
/* Parse the initializer. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
{
@@ -22492,6 +22494,7 @@ cp_parser_init_declarator (cp_parser* parser,
{
is_initialized = SD_INITIALIZED;
initialization_kind = token->type;
+ declarator->init_loc = token->location;
if (maybe_range_for_decl)
*maybe_range_for_decl = error_mark_node;
tmp_init_loc = token->location;
@@ -24751,6 +24754,8 @@ cp_parser_parameter_declaration (cp_parser *parser,
{
tree type = decl_specifiers.type;
token = cp_lexer_peek_token (parser->lexer);
+ if (declarator)
+ declarator->init_loc = token->location;
/* If we are defining a class, then the tokens that make up the
default argument must be saved and processed later. */
if (!template_parm_p && at_class_scope_p ()
@@ -27143,6 +27148,7 @@ cp_parser_member_declaration (cp_parser* parser)
constant-initializer. When we call `grokfield', it will
perform more stringent semantics checks. */
initializer_token_start = cp_lexer_peek_token (parser->lexer);
+ declarator->init_loc = initializer_token_start->location;
if (function_declarator_p (declarator)
|| (decl_specifiers.type
&& TREE_CODE (decl_specifiers.type) == TYPE_DECL
@@ -27171,6 +27177,8 @@ cp_parser_member_declaration (cp_parser* parser)
&& !function_declarator_p (declarator))
{
bool x;
+ declarator->init_loc
+ = cp_lexer_peek_token (parser->lexer)->location;
if (decl_specifiers.storage_class != sc_static)
initializer = cp_parser_save_nsdmi (parser);
else