Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ld resolving different types

0 views
Skip to first unread message

Norman Goldstein

unread,
Feb 15, 2020, 7:51:23 PM2/15/20
to bug-gn...@gnu.org
LD version:
   GNU ld version 2.31.1-37.fc30

Platform:
   Linux 5.4.17-100.fc30.x86_64 #1 SMP     x86_64 x86_64 x86_64 GNU/Linux

Compile/Link command:
    gcc tlink.cpp tlink2.cpp -o tlink -lstdc++

The programs compiles and links without warning or error, but resolves
/extern int foo/ with /double foo/.  The result of running the program
is, of course, garbage:

foo= -858993459

The program contains only 1 definition for foo (the extern statement is
a declaration), so the program is not violating the One Definition Rule.

Thank you.



tlink.cpp
tlink2.cpp

Andreas Schwab

unread,
Feb 16, 2020, 3:06:44 AM2/16/20
to Norman Goldstein, bug-gn...@gnu.org
This violates the rule on type identity [basic.link], no diagnostic required.

Andreas.

--
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."

0 new messages