public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/110761] New: No warning for an uninitialized variable when used within its own initialization
@ 2023-07-21 8:04 jwzeng at nuaa dot edu.cn
2023-07-21 9:34 ` [Bug middle-end/110761] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-07-21 8:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110761
Bug ID: 110761
Summary: No warning for an uninitialized variable when used
within its own initialization
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: jwzeng at nuaa dot edu.cn
Target Milestone: ---
Link to the Compiler Explorer: https://godbolt.org/z/ra7P3EcMn
There is no warning for a variable is uninitialized when used within its own
initialization.
$ cat test.c
int main(void)
{
int a = 1, b = 2;
int g = (a % ((~0) && b)) && g;
}
$ gcc-trunk -Wall -Wextra -pedantic -c test.c
$
$ clang-16.0.0 -Weverything -pedantic -c test.c
test.c:4:34: warning: variable 'g' is uninitialized when used within its own
initialization [-Wuninitialized]
int g = (a % ((~0) && b)) && g;
~ ^
1 warning generated.
$
$ gcc-trunk -v
gcc (GCC) 14.0.0 20230619 (experimental) [master r14-1917-gf8e0270272]
$ clang-16.0.0 -v
clang version 16.0.0
Target: x86_64-unknown-linux-gnu
Would it be better to output warning information like clang? In gcc-11.4 and
earlier versions, there will be corresponding warnings.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/110761] No warning for an uninitialized variable when used within its own initialization
2023-07-21 8:04 [Bug middle-end/110761] New: No warning for an uninitialized variable when used within its own initialization jwzeng at nuaa dot edu.cn
@ 2023-07-21 9:34 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-21 9:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110761
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Because g is only used conditionally and that condition is false. Does
clang diagnose
int g = 0 && g;
?
if you write
int g = 1 && g;
we diagnose the use.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-21 9:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 8:04 [Bug middle-end/110761] New: No warning for an uninitialized variable when used within its own initialization jwzeng at nuaa dot edu.cn
2023-07-21 9:34 ` [Bug middle-end/110761] " rguenth 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).