https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87905

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Raymond Jennings from comment #4)
> (In reply to Martin Liška from comment #2)
> > > 
> > > Note in the test package that neither struct is exposed to the other
> > > translation unit.
> > 
> > But it's violation of C++ ODR and as LTO compilation unit is entire program,
> > you then introduce violation.
> 
> I respectfully disagree.
> 
> Unless the source code itself changes, toggling LTO shouldn't affect
> generated warnings.

That's not true. Your source code snippet is violating ODR even without LTO,
but compiler can't prove that.

> 
> It may be one /compilation/ unit, but by the standard they still count as
> separate translation units.  LTO is an artifact of the compiler and not the
> standard so it shouldn't have an impact on ODR warnings.

Please take a look at:
https://en.wikipedia.org/wiki/One_Definition_Rule

more particularly at 'Example showing unexpected side effects' where you can
see example where even non-LTO mode produces undefined behavior based on the
violation.

In general, we as compiler developers, are under pressure due to user's
expectation about highly optimized binaries. On the other hand, we need to base
these optimizations on standards that we can leverage.

Reply via email to