Re: Bug in the linker

johnny dude <[email protected]> Wed, 21 Aug 2019 19:43:25 +0300
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <CAKSZggg1Lk01bQ760WhYikm9=a3OBXawwaQYF7+p7aAeddvi8A@mail.gmail.com>
Thank you for the quick response.

I understand the violation.

In all other cases ld returns an error of: "multiple definitions".
Including the same code, with the constructor defined outside the struct
declaration.

I thought it might be an implementation detail.

On Wed, Aug 21, 2019 at 5:09 PM Andreas Schwab <[email protected]>
wrote:

> On Aug 21 2019, johnny dude <[email protected]> wrote:
>
> > 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; }
>
> This violates basic.def.odr.
>
> Andreas.
>
> --
> Andreas Schwab, [email protected]
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
>