public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type
@ 2022-08-31 19:20 pavel.morozkin at gmail dot com
2022-08-31 19:24 ` [Bug c/106797] " jsm28 at gcc dot gnu.org
2022-08-31 19:28 ` pavel.morozkin at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: pavel.morozkin at gmail dot com @ 2022-08-31 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106797
Bug ID: 106797
Summary: Improvement: diagnose undefined behavior: not all
declarations that refer to the same object or function
have compatible type
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pavel.morozkin at gmail dot com
Target Milestone: ---
This code:
static int (*x)[];
void f1(void)
{
extern int (*x)[3];
}
void f2(void)
{
extern int (*x)[5];
}
compiled with -std=c11 -pedantic -Wall -Wextra -Wno-unused-variable triggers UB
(see below) and leads to no diagnostics. It is proposed to produce this (or
similar) diagnostics: "not all declarations that refer to the same object x
have compatible type" OR "declarations that refer to the same object x have
types 'int (*)[5]' and 'int (*)[3]' which are not compatible".
Relevant quote from C11, 6.2.7 Compatible type and composite type, 2:
> All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.
In the program above types 'int (*)[5]' and 'int (*)[3]' are not compatible. It
is useful to diagnose that.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/106797] Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type
2022-08-31 19:20 [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type pavel.morozkin at gmail dot com
@ 2022-08-31 19:24 ` jsm28 at gcc dot gnu.org
2022-08-31 19:28 ` pavel.morozkin at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2022-08-31 19:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106797
Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #1 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
See bug 21343.
*** This bug has been marked as a duplicate of bug 21343 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/106797] Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type
2022-08-31 19:20 [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type pavel.morozkin at gmail dot com
2022-08-31 19:24 ` [Bug c/106797] " jsm28 at gcc dot gnu.org
@ 2022-08-31 19:28 ` pavel.morozkin at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: pavel.morozkin at gmail dot com @ 2022-08-31 19:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106797
--- Comment #2 from Pavel M <pavel.morozkin at gmail dot com> ---
Observation: if "static" is removed, then GCC generates:
<source>: In function 'f2':
<source>:10:18: error: conflicting types for 'x'; have 'int (*)[5]'
10 | extern int (*x)[5];
| ^
<source>:5:18: note: previous declaration of 'x' with type 'int (*)[3]'
5 | extern int (*x)[3];
|
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-31 19:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31 19:20 [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type pavel.morozkin at gmail dot com
2022-08-31 19:24 ` [Bug c/106797] " jsm28 at gcc dot gnu.org
2022-08-31 19:28 ` pavel.morozkin at gmail 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).