public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
@ 2020-05-12 11:28 ` chrubis at suse dot cz
2022-03-22 18:36 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: chrubis at suse dot cz @ 2020-05-12 11:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
Cyril Hrubis <chrubis at suse dot cz> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |chrubis at suse dot cz
--- Comment #4 from Cyril Hrubis <chrubis at suse dot cz> ---
Created attachment 48519
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48519&action=edit
Simplified reproducer.
I got a plenty of these useless warnings as well for LTP
https://github.com/linux-test-project/ltp.
It also looks like the warning is not printed in the compound literal is last
in the structure. In my case swapping struct bar *b and int a silences the
warning.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
2020-05-12 11:28 ` [Bug c/84685] Designated initializers warning chrubis at suse dot cz
@ 2022-03-22 18:36 ` mpolacek at gcc dot gnu.org
2022-03-22 20:41 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-22 18:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
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
CC| |mpolacek at gcc dot gnu.org
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have a patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
2020-05-12 11:28 ` [Bug c/84685] Designated initializers warning chrubis at suse dot cz
2022-03-22 18:36 ` mpolacek at gcc dot gnu.org
@ 2022-03-22 20:41 ` cvs-commit at gcc dot gnu.org
2022-03-22 20:43 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-22 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
--- Comment #6 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:4b7d9f8f51bd96d290aac230c71e501fcb6b21a6
commit r12-7772-g4b7d9f8f51bd96d290aac230c71e501fcb6b21a6
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Mar 22 14:37:02 2022 -0400
c: -Wmissing-field-initializers and designated inits [PR82283, PR84685]
This patch fixes two kinds of wrong -Wmissing-field-initializers
warnings. Our docs say that this warning "does not warn about designated
initializers", but we give a warning for
1) the array case:
struct S {
struct N {
int a;
int b;
} c[1];
} d = {
.c[0].a = 1,
.c[0].b = 1, // missing initializer for field 'b' of 'struct N'
};
we warn because push_init_level, when constructing an array, clears
constructor_designated (which the warning relies on), and we forget
that we were in a designated initializer context. Fixed by the
push_init_level hunk; and
2) the compound literal case:
struct T {
int a;
int *b;
int c;
};
struct T t = { .b = (int[]){1} }; // missing initializer for field 'c' of
'struct T'
where set_designator properly sets constructor_designated to 1, but the
compound literal causes us to create a whole new initializer_stack in
start_init, which clears constructor_designated. Then, after we've parsed
the compound literal, finish_init flushes the initializer_stack entry,
but doesn't restore constructor_designated, so we forget we were in
a designated initializer context, which causes the bogus warning. (The
designated flag is also tracked in constructor_stack, but in this case,
we didn't perform push_init_level between set_designator and start_init
so it wasn't saved anywhere.)
PR c/82283
PR c/84685
gcc/c/ChangeLog:
* c-typeck.cc (struct initializer_stack): Add 'designated' member.
(start_init): Set it.
(finish_init): Restore constructor_designated.
(push_init_level): Set constructor_designated to the value of
constructor_designated in the upper constructor_stack.
gcc/testsuite/ChangeLog:
* gcc.dg/Wmissing-field-initializers-1.c: New test.
* gcc.dg/Wmissing-field-initializers-2.c: New test.
* gcc.dg/Wmissing-field-initializers-3.c: New test.
* gcc.dg/Wmissing-field-initializers-4.c: New test.
* gcc.dg/Wmissing-field-initializers-5.c: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2022-03-22 20:41 ` cvs-commit at gcc dot gnu.org
@ 2022-03-22 20:43 ` mpolacek at gcc dot gnu.org
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-22 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch seems safe to backport to 11.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2022-03-22 20:43 ` mpolacek at gcc dot gnu.org
@ 2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-29 1:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:0fa9022aa30b9c4dde965a0406943c8c0af5eb54
commit r11-9715-g0fa9022aa30b9c4dde965a0406943c8c0af5eb54
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Mar 22 14:37:02 2022 -0400
c: -Wmissing-field-initializers and designated inits [PR82283, PR84685]
This patch fixes two kinds of wrong -Wmissing-field-initializers
warnings. Our docs say that this warning "does not warn about designated
initializers", but we give a warning for
1) the array case:
struct S {
struct N {
int a;
int b;
} c[1];
} d = {
.c[0].a = 1,
.c[0].b = 1, // missing initializer for field 'b' of 'struct N'
};
we warn because push_init_level, when constructing an array, clears
constructor_designated (which the warning relies on), and we forget
that we were in a designated initializer context. Fixed by the
push_init_level hunk; and
2) the compound literal case:
struct T {
int a;
int *b;
int c;
};
struct T t = { .b = (int[]){1} }; // missing initializer for field 'c' of
'struct T'
where set_designator properly sets constructor_designated to 1, but the
compound literal causes us to create a whole new initializer_stack in
start_init, which clears constructor_designated. Then, after we've parsed
the compound literal, finish_init flushes the initializer_stack entry,
but doesn't restore constructor_designated, so we forget we were in
a designated initializer context, which causes the bogus warning. (The
designated flag is also tracked in constructor_stack, but in this case,
we didn't perform push_init_level between set_designator and start_init
so it wasn't saved anywhere.)
PR c/82283
PR c/84685
gcc/c/ChangeLog:
* c-typeck.c (struct initializer_stack): Add 'designated' member.
(start_init): Set it.
(finish_init): Restore constructor_designated.
(push_init_level): Set constructor_designated to the value of
constructor_designated in the upper constructor_stack.
gcc/testsuite/ChangeLog:
* gcc.dg/Wmissing-field-initializers-1.c: New test.
* gcc.dg/Wmissing-field-initializers-2.c: New test.
* gcc.dg/Wmissing-field-initializers-3.c: New test.
* gcc.dg/Wmissing-field-initializers-4.c: New test.
* gcc.dg/Wmissing-field-initializers-5.c: New test.
(cherry picked from commit 4b7d9f8f51bd96d290aac230c71e501fcb6b21a6)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/84685] Designated initializers warning
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
@ 2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-29 1:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 11+.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-03-29 1:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-84685-4@http.gcc.gnu.org/bugzilla/>
2020-05-12 11:28 ` [Bug c/84685] Designated initializers warning chrubis at suse dot cz
2022-03-22 18:36 ` mpolacek at gcc dot gnu.org
2022-03-22 20:41 ` cvs-commit at gcc dot gnu.org
2022-03-22 20:43 ` mpolacek at gcc dot gnu.org
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
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).