ld resolving different types

Norman Goldstein <[email protected]> Sat, 15 Feb 2020 16:51:14 -0800
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
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 (text/x-c++src, 152 B)
#include <iostream>
using namespace std;

extern int foo;

int main( int argc, char* argv[] )
{
  cout << "foo= " << foo << endl;

  return 0;
}// main
tlink2.cpp (text/x-c++src, 18 B)
double foo = 2.1;