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

--- Comment #12 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
(In reply to Bernardo Negri from comment #11)
> (In reply to Nathaniel Shead from comment #10)
> > Unfortunately not, the header would need to be fixed.  For what it's worth,
> > if the header was included in more than one TU this was always IFNDR
> > (ill-formed, no diagnostic required) due to the ODR violation; modules has
> > just made this mandated IF (ill-formed) in more cases.
> 
> Would it be IFNDR even if it had an include guard (or pragma once). From my
> understanding of the spec, it would be IFNDR because of [1] and [2]: there
> would be two different definitions of Class in different TUs (so [1] would
> apply), but getSize would refer to different entities (that are defined the
> same way). Therefore, the existence of both of these definitions would run
> afoul of basic.def.odr#16.5: "corresponding names, looked up according to
> [basic.lookup], shall denote the same entity". Am I correct? Or do the
> templates mess everything up?
> 
> [1] https://eel.is/c++draft/basic.def.odr#16
> [2] https://eel.is/c++draft/basic.link#8

Correct, include guards (and #pragma once) just prevent the same file being
included within the same TU; without this we could get multiple definitions
visible from each other (which is ill-formed, with diagnostic required).  But
across different TUs the compiler can't in general tell that they're
mismatching, hence the IFNDR, as you point out.

Reply via email to