public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object
@ 2004-03-29 11:59 algrant at acm dot org
2004-03-29 12:15 ` [Bug c++/14769] " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: algrant at acm dot org @ 2004-03-29 11:59 UTC (permalink / raw)
To: gcc-bugs
In the following it is clear from the example in the C++ Standard 3.5.#6 that
the block extern declaration refers to a separate object, i.e. that there is an
internal-linkage i and an external-linkage i in the same TU. As in C a block
extern that does not 'see' an internal-linkage declaration (as in this case
where hidden by the formal) gets external linkage; C 6.2.2#7 says that having
internal and external linkage for the same name is UB but no such prohibition
applies in C++. G++ incorrectly resolves the block extern to the file-scope
object (which in C++ is internal linkage) but should instead generate an
external reference for the i object that is declared in the block extern.
#include <stdio.h>
const int i = 123;
int main(int i, char **) {
{
extern int i;
printf("i = %u\n", i);
}
return 0;
}
--
Summary: Block extern incorrectly resolved to file-scope internal
linkage object
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: algrant at acm dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] Block extern incorrectly resolved to file-scope internal linkage object
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
@ 2004-03-29 12:15 ` pinskia at gcc dot gnu dot org
2004-03-29 14:31 ` algrant at acm dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-29 12:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-29 12:15 -------
It seems to work correctly for me (for -fPIC and without I will only show with):
(without the extern int i;):
main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
call .LPR3
addl $_GLOBAL_OFFSET_TABLE_, %ebx
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl 8(%ebp), %eax
movl %eax, 4(%esp)
leal .LC0@GOTOFF(%ebx), %eax
movl %eax, (%esp)
call printf@PLT
movl $0, %eax
movl -4(%ebp), %ebx
leave
ret
See how there is no reference to i, meaning that i is already "inlined".
Here are the asm for with the "extern int i;":
main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
call .LPR3
addl $_GLOBAL_OFFSET_TABLE_, %ebx
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl i@GOT(%ebx), %eax
movl (%eax), %eax
movl %eax, 4(%esp)
leal .LC0@GOTOFF(%ebx), %eax
movl %eax, (%esp)
call printf@PLT
movl $0, %eax
movl -4(%ebp), %ebx
leave
ret
See how it goes through GOT,meaning it will pick up the extern one and not really always the local one.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] Block extern incorrectly resolved to file-scope internal linkage object
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
2004-03-29 12:15 ` [Bug c++/14769] " pinskia at gcc dot gnu dot org
@ 2004-03-29 14:31 ` algrant at acm dot org
2004-03-30 18:07 ` [Bug c++/14769] [DR 426] " pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: algrant at acm dot org @ 2004-03-29 14:31 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From algrant at acm dot org 2004-03-29 14:31 -------
1) add a second translation unit
extern int i = 5;
2) compile, link, and run the two translation units. If it prints 5 it's ok,
if it prints 123 it's broken. For me it prints 123.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
2004-03-29 12:15 ` [Bug c++/14769] " pinskia at gcc dot gnu dot org
2004-03-29 14:31 ` algrant at acm dot org
@ 2004-03-30 18:07 ` pinskia at gcc dot gnu dot org
2004-03-30 18:09 ` pinskia at gcc dot gnu dot org
2004-09-28 3:36 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-30 18:07 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-30 18:07 -------
This looks related to DR 426: <http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#426>.
so confirming to ...
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-03-30 18:07:41
date| |
Summary|Block extern incorrectly |[DR 426] Block extern
|resolved to file-scope |incorrectly resolved to
|internal linkage object |file-scope internal linkage
| |object
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
` (2 preceding siblings ...)
2004-03-30 18:07 ` [Bug c++/14769] [DR 426] " pinskia at gcc dot gnu dot org
@ 2004-03-30 18:09 ` pinskia at gcc dot gnu dot org
2004-09-28 3:36 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-30 18:09 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-30 18:09 -------
Suspended as it is still active (because they are drafting the resulotion) but it looks like it is going to be
undefined behavior so GCC is "right".
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |SUSPENDED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
` (3 preceding siblings ...)
2004-03-30 18:09 ` pinskia at gcc dot gnu dot org
@ 2004-09-28 3:36 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-28 3:36 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Last reconfirmed|2004-06-29 02:03:16 |2004-09-28 03:36:55
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
[not found] <bug-14769-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:38 ` pinskia at gcc dot gnu.org
@ 2021-12-17 11:40 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 11:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tabloid.adroit at gmail dot com
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 94764 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
[not found] <bug-14769-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-17 11:38 ` pinskia at gcc dot gnu.org
2021-12-17 11:40 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 11:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|wrong-code |accepts-invalid
Blocks| |94404
Alias| |cwg426
Status|SUSPENDED |NEW
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> [Adopted at the February/March, 2017 meeting.]
The defect report has now been adopted for C++20, and the code is illformed
(invalid).
I don't know if this is illformed with no diagnostic required or not but I
suspect it requires a diagnostic.
So now this is an accepts invalid.
Also note clang rejects the example program in comment #0 as illformed already
as the types are different const int vs int.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94404
[Bug 94404] [meta-bug] C++ core issues
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/14769] [DR 426] Block extern incorrectly resolved to file-scope internal linkage object
[not found] <bug-14769-1535@http.gcc.gnu.org/bugzilla/>
@ 2009-11-26 3:31 ` pi3orama at gmail dot com
0 siblings, 0 replies; 9+ messages in thread
From: pi3orama at gmail dot com @ 2009-11-26 3:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pi3orama at gmail dot com 2009-11-26 03:31 -------
How about the below C++ program? According to recent draft, the func() in //2:
is clearly "internal linkage", but g++ resolve it as external linkage.
static void func() { }
int main()
{
extern void func();
func(); // 1:
{
extern void func();
func(); //2:
}
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14769
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-12-17 11:40 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-29 11:59 [Bug c++/14769] New: Block extern incorrectly resolved to file-scope internal linkage object algrant at acm dot org
2004-03-29 12:15 ` [Bug c++/14769] " pinskia at gcc dot gnu dot org
2004-03-29 14:31 ` algrant at acm dot org
2004-03-30 18:07 ` [Bug c++/14769] [DR 426] " pinskia at gcc dot gnu dot org
2004-03-30 18:09 ` pinskia at gcc dot gnu dot org
2004-09-28 3:36 ` pinskia at gcc dot gnu dot org
[not found] <bug-14769-1535@http.gcc.gnu.org/bugzilla/>
2009-11-26 3:31 ` pi3orama at gmail dot com
[not found] <bug-14769-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:38 ` pinskia at gcc dot gnu.org
2021-12-17 11:40 ` pinskia 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).