public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode
@ 2021-11-21 12:13 fchelnokov at gmail dot com
2021-11-21 14:50 ` [Bug c++/103347] " pinskia at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: fchelnokov at gmail dot com @ 2021-11-21 12:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Bug ID: 103347
Summary: Non-static data member initialization is erroneously
allowed in C++03 mode
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
This code is invalid in C++03 mode:
```
#include <cstddef>
struct test {
void *x = NULL; //invalid in C++03 mode
};
int main() {}
```
It is rejected by Clang, not not by GCC. Demo:
https://gcc.godbolt.org/z/113EWvzzx
Related discussion: https://stackoverflow.com/q/49618716/7325599
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
@ 2021-11-21 14:50 ` pinskia at gcc dot gnu.org
2021-11-21 14:52 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-21 14:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is macro tracking which is getting in the way of emitting the warning as
NULL is from a system header, there is a dup of this bug already.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
2021-11-21 14:50 ` [Bug c++/103347] " pinskia at gcc dot gnu.org
@ 2021-11-21 14:52 ` pinskia at gcc dot gnu.org
2021-11-21 14:54 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-21 14:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is GCC does warning about the following case:
struct test {
int x = 0;
};
int main() {}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
2021-11-21 14:50 ` [Bug c++/103347] " pinskia at gcc dot gnu.org
2021-11-21 14:52 ` pinskia at gcc dot gnu.org
@ 2021-11-21 14:54 ` pinskia at gcc dot gnu.org
2021-11-21 17:02 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-21 14:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 77513
*** This bug has been marked as a duplicate of bug 77513 ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (2 preceding siblings ...)
2021-11-21 14:54 ` pinskia at gcc dot gnu.org
@ 2021-11-21 17:02 ` redi at gcc dot gnu.org
2021-11-22 9:37 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-21 17:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> That is GCC does warning about the following case:
> struct test {
> int x = 0;
> };
> int main() {}
And you get an error with -pedantic-errors
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (3 preceding siblings ...)
2021-11-21 17:02 ` redi at gcc dot gnu.org
@ 2021-11-22 9:37 ` pinskia at gcc dot gnu.org
2021-11-22 9:38 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-22 9:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually this is a dup of bug 57201.
*** This bug has been marked as a duplicate of bug 57201 ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (4 preceding siblings ...)
2021-11-22 9:37 ` pinskia at gcc dot gnu.org
@ 2021-11-22 9:38 ` pinskia at gcc dot gnu.org
2021-11-22 9:47 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-22 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Let's mark this as a dup of bug 77299.
*** This bug has been marked as a duplicate of bug 77299 ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] Non-static data member initialization is erroneously allowed in C++03 mode
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (5 preceding siblings ...)
2021-11-22 9:38 ` pinskia at gcc dot gnu.org
@ 2021-11-22 9:47 ` pinskia at gcc dot gnu.org
2021-11-22 9:53 ` [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL pinskia at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-22 9:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|DUPLICATE |---
Status|RESOLVED |NEW
Last reconfirmed| |2021-11-22
Ever confirmed|0 |1
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually let's reopen this one too.
It might be a different bug from PR 77299 ...
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (6 preceding siblings ...)
2021-11-22 9:47 ` pinskia at gcc dot gnu.org
@ 2021-11-22 9:53 ` pinskia at gcc dot gnu.org
2021-11-22 16:43 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-22 9:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (7 preceding siblings ...)
2021-11-22 9:53 ` [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL pinskia at gcc dot gnu.org
@ 2021-11-22 16:43 ` jakub at gcc dot gnu.org
2021-11-22 18:19 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-11-22 16:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dmalcolm at gcc dot gnu.org,
| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Perhaps a faster way to fix this would be to try to warn on the = token rather
than on input_location which happens to be the location of NULL after
cp_parser_cache_defarg went through it.
For
struct test {
int x = 1 + 2; //invalid in C++03 mode
};
we strangely warn with caret on the 2, for int x = (1 + 2); with caret on )
etc.
maybe_warn_cpp0x doesn't really take a location_t though, probably it should.
And grokdeclarator isn't called with the actual initializer (DEFERRED_PARSE)
from which we could dig up the location of the first token.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (8 preceding siblings ...)
2021-11-22 16:43 ` jakub at gcc dot gnu.org
@ 2021-11-22 18:19 ` mpolacek at gcc dot gnu.org
2021-11-24 5:24 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-22 18:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #8)
> And grokdeclarator isn't called with the actual initializer (DEFERRED_PARSE)
> from which we could dig up the location of the first token.
True, though cp_parser_member_declaration has initializer_token_start which
carries the location of the '='. I suppose we could add another location_t to
cp_declarator for init-declarators, and then just use it.
For which I have a patch:
$ ./cc1plus -quiet 103347.C -std=c++03
103347.C:3:13: warning: non-static data member initializers only available with
‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
3 | void *x = NULL; //invalid in C++03 mode
| ^
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (9 preceding siblings ...)
2021-11-22 18:19 ` mpolacek at gcc dot gnu.org
@ 2021-11-24 5:24 ` cvs-commit at gcc dot gnu.org
2021-11-24 5:26 ` [Bug c++/103347] [9/10/11 " mpolacek at gcc dot gnu.org
2021-12-01 2:51 ` ensadc at mailnesia dot com
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-24 5:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:d71d019f63ed5d3fdb34579023bafa4dcf323f2c
commit r12-5488-gd71d019f63ed5d3fdb34579023bafa4dcf323f2c
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Nov 22 14:09:25 2021 -0500
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.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (10 preceding siblings ...)
2021-11-24 5:24 ` cvs-commit at gcc dot gnu.org
@ 2021-11-24 5:26 ` mpolacek at gcc dot gnu.org
2021-12-01 2:51 ` ensadc at mailnesia dot com
12 siblings, 0 replies; 14+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-24 5:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Summary|[9/10/11/12 Regression] |[9/10/11 Regression]
|Non-static data member |Non-static data member
|initialization is |initialization is
|erroneously allowed in |erroneously allowed in
|C++03 with assignment to |C++03 with assignment to
|NULL |NULL
--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 12.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103347] [9/10/11 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
` (11 preceding siblings ...)
2021-11-24 5:26 ` [Bug c++/103347] [9/10/11 " mpolacek at gcc dot gnu.org
@ 2021-12-01 2:51 ` ensadc at mailnesia dot com
12 siblings, 0 replies; 14+ messages in thread
From: ensadc at mailnesia dot com @ 2021-12-01 2:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103347
ensadc at mailnesia dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ensadc at mailnesia dot com
--- Comment #12 from ensadc at mailnesia dot com ---
*** Bug 66839 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2021-12-01 2:51 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-21 12:13 [Bug c++/103347] New: Non-static data member initialization is erroneously allowed in C++03 mode fchelnokov at gmail dot com
2021-11-21 14:50 ` [Bug c++/103347] " pinskia at gcc dot gnu.org
2021-11-21 14:52 ` pinskia at gcc dot gnu.org
2021-11-21 14:54 ` pinskia at gcc dot gnu.org
2021-11-21 17:02 ` redi at gcc dot gnu.org
2021-11-22 9:37 ` pinskia at gcc dot gnu.org
2021-11-22 9:38 ` pinskia at gcc dot gnu.org
2021-11-22 9:47 ` pinskia at gcc dot gnu.org
2021-11-22 9:53 ` [Bug c++/103347] [9/10/11/12 Regression] Non-static data member initialization is erroneously allowed in C++03 with assignment to NULL pinskia at gcc dot gnu.org
2021-11-22 16:43 ` jakub at gcc dot gnu.org
2021-11-22 18:19 ` mpolacek at gcc dot gnu.org
2021-11-24 5:24 ` cvs-commit at gcc dot gnu.org
2021-11-24 5:26 ` [Bug c++/103347] [9/10/11 " mpolacek at gcc dot gnu.org
2021-12-01 2:51 ` ensadc at mailnesia dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).