So, I have this code in two separate translation units:
When compiling, usually the result is 10 . When compiled with -O3 (insert on), I get 11 .
I explicitly violated the ODR for func() .
It appeared when I started merging sources of different dlls with fewer DLLs.
I tried:
- GCC 5.1
-Wodr (which requires -flto ) - gold linker with
-detect-odr-violations ASAN_OPTIONS=detect_odr_violation=1 before running the tool binary with the sanitizer.
Asanas can allegedly catch other ODR violations (global varnas with different types or something like that)
This is a really nasty problem in C ++, and I am amazed there is no reliable toolkit to detect it.
Perhaps I misused one of the tools I tried? Or is there another tool for this?
EDIT
The problem goes unnoticed even when I make 2 func() implementations very different, so they do not compile with the same number of instructions.
It also affects class methods defined inside the class body - they are implicitly inlined.
An outdated code with a lot of copies / pastes + minor changes after that is a joy.
c ++ linker g ++ one-definition-rule linker-errors
onqtam
source share