[llvm-bugs] [Bug 35566] New: missed warning for ODR violation.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 7 13:22:01 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35566

            Bug ID: 35566
           Summary: missed warning for ODR violation.
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pawel_sikora at zoho.com
                CC: llvm-bugs at lists.llvm.org

% 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

<no warning>


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; };
        ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171207/8e5eb22a/attachment.html>


More information about the llvm-bugs mailing list