Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.utils.bug > #2264

Bug in the linker

From johnny dude <johnny.dude@gmail.com>
Newsgroups gnu.utils.bug
Subject Bug in the linker
Date 2019-08-21 14:59 +0300
Message-ID <mailman.585.1566395340.30381.bug-gnu-utils@gnu.org> (permalink)
References <CAKSZggjeNyRv_f+Wc_E4VpnQSZCKsQi8LgxmzMBbDzwJE2vDBA@mail.gmail.com>

Show all headers | View raw


Hi,

I found a possible bug, ld does not produce an error message: "multiple
definitions" when it is a constructor defined in the structure declaration.

How to reproduce it:
I'm using the gcc:9.2.0 docker, created two files and the result listed
below:

root@44027fc60f45:/# cat a.cpp
#include <iostream>
struct A { int n; A(int n) : n(n + 10) {} };
int a(int n) { return A(n).n; }
extern int b(int n);
int main(int, char**) { std::clog << a(5) << ", " << b(5) << "\n"; }

root@44027fc60f45:/# cat b.cpp
#include <iostream>
struct A { int n; A(int n) : n(n + 100) {} };
int b(int n) { return A(n).n; }

root@44027fc60f45:/# g++ a.cpp b.cpp -o ab && ./ab
15, 15

root@44027fc60f45:/# g++ b.cpp a.cpp -o ba && ./ba
105, 105
root@44027fc60f45:/#

Back to gnu.utils.bug | Previous | Next | Find similar


Thread

Bug in the linker johnny dude <johnny.dude@gmail.com> - 2019-08-21 14:59 +0300

csiph-web