This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug lto/67357] -Wodr warnings from types in anonymous namespace
- From: "rogero at howzatt dot demon.co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 26 Aug 2015 09:40:02 +0000
- Subject: [Bug lto/67357] -Wodr warnings from types in anonymous namespace
- Auto-submitted: auto-generated
- References: <bug-67357-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67357
--- Comment #2 from Roger Orr <rogero at howzatt dot demon.co.uk> ---
The fault still occurs on gcc-5-branch, does not occur on gcc trunk.
I have also found that making a small change to the example in comment 5 of PR
66180 makes that fail with gcc 5.2.0: adding const to the type used for the
unique pointers.
The modified example becomes:
$ cat foo1.cpp
#include <memory>
namespace {
class A {
int i;
};
}
class G {
std::unique_ptr<const A> foo() const;
};
std::unique_ptr<const A> G::foo() const { return std::make_unique<const A>(); }
$ cat foo2.cpp
#include <memory>
namespace {
class A {
bool a;
};
}
class H {
std::unique_ptr<const A> bar() const;
};
std::unique_ptr<const A> H::bar() const { return std::make_unique<const A>(); }
$ /opt/gcc-5-branch/bin/g++ -std=c++14 -flto foo1.cpp foo2.cpp
/opt/gcc-5-branch/include/c++/5.2.1/bits/unique_ptr.h:151:41: warning: type
'const struct element_type' violates one definition rule [-Wodr]
typedef _Tp element_type;
^
/opt/gcc-5-branch/include/c++/5.2.1/bits/unique_ptr.h:151:41: note: a different
type is defined in another translation unit
typedef _Tp element_type;
^
foo1.cpp:4:7: note: the first difference of corresponding definitions is field
'i'
int i;
^
foo2.cpp:4:8: note: a field with different name is defined in another
translation unit
bool a;
^
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
whereas:
$ /opt/gcc-trunk/bin/g++ -flto -std=c++14 -flto foo1.cpp foo2.cpp
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status