Skip to content

missed warning for ODR violation. #34914

@pawelsopensource

Description

@pawelsopensource
Bugzilla Link 35566
Version 5.0
OS Linux
CC @adrian-prantl,@dwblaikie,@pogo59

Extended Description

% cat tu1.cpp
struct S { int i = 0; };
S foo() { return S(); }

% cat tu2.cpp
struct S { double i = 0.0; };
S bar() { return S(); }

% clang++ -Wodr -std=c++1y -fPIC -flto tu1.cpp tu2.cpp -c
% clang++ -Wodr -std=c++1y -fPIC -flto -shared tu1.o tu2.o -o tu.so -fuse-ld=lld

from the other side, g++ 6.3.1 reports ODR violation.

% g++ -Wodr -std=c++1y -fPIC -flto tu1.cpp tu2.cpp -c
% g++ -Wodr -std=c++1y -fPIC -flto -shared tu1.o tu2.o -o tu.so -fuse-ld=gold
tu1.cpp:1:8: warning: type ‘struct S’ violates the C++ One Definition Rule [-Wodr]
struct S { int i = 0; };
^
tu2.cpp:1:8: note: a different type is defined in another translation unit
struct S { double i = 0.0; };
^
tu1.cpp:1:20: note: the first difference of corresponding definitions is field ‘i’
struct S { int i = 0; };
^
tu2.cpp:1:23: note: a field of same name but different type is defined in another translation unit
struct S { double i = 0.0; };
^
tu1.cpp:1:8: note: type ‘int’ should match type ‘double’
struct S { int i = 0; };
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    LTOLink time optimization (regular/full LTO or ThinLTO)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions