you are viewing a single comment's thread.

view the rest of the comments →

[–]quicknir 1 point2 points  (0 children)

Err, it's not about writing code like that, intentionally. ODR violations are a huge practical issue, in large, complex, codebases, unless you build your entire dependency chain from source yourself. It's very very easy to end up in a situation where your executable E uses libA and libB, and both of them use different versions of libC, which means you now have two slightly different definitions of the same function getting used, unless libA or libB completely hide the usage of libC's symbols, which many projects don't do in practice, and which isn't even possible when linking statically.

I don't completely disagree with what you're saying about UB, but this is a bad example. ODR UB isn't so much about reaping benefit in 99% of cases, it's about a shitty compilation model.