c++: Fix missing NSDMI diagnostic in C++98 [PR103347]
commitd71d019f63ed5d3fdb34579023bafa4dcf323f2c
authorMarek Polacek <polacek@redhat.com>
Mon, 22 Nov 2021 19:09:25 +0000 (22 14:09 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 24 Nov 2021 05:22:10 +0000 (24 00:22 -0500)
tree21384cd37c5ec8783cd0e7463c81c87f7f12c9eb
parent9bf69a8558638ce0cdd69e83a68776deb9b8e053
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.
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/error.c
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/nsdmi-warn1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi-warn1.h [new file with mode: 0644]