https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102092
--- Comment #3 from David Friberg <davveston at gmail dot com> --- (In reply to David Friberg from comment #2) > I believe your program has UB as it contains an odr-violation due to the > friend declaration of the stream operator function , as its in-class > definition ("hidden friend") makes use of the non-type template parameter > 'Degree'. > > The hidden friend, albeit being inline (protection against multiple-TU > odr-violations, given token-by-token identical definitions), will have > multiple definitions that are not the same as soon as two specializations of > the class template 'Polynomial' are instantiated if these two > specializations differ in the 'Degree' template parameter. > > Recall that a non-template friend of a class template is in itself not a > templated entity, but a namespace-scope function. Never mind, I realized the hidden friend uses the class template as an argument, though, so each specialization will instantiate a separate overload, so I guess there will be no odr-violation Nafter all.