On Mon, 7 Oct 2024 at 10:10, R. Diez via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > Hi all: > > Sometimes, when I convert a function to a C++ template, I forget to remove > the 'static' or 'inline' attributes: > > template< typename IntegerType > > static inline // Unnecessary > IntegerType my_template ( IntegerType v ) > { > return v; > } > > int main ( void ) > { > return my_template( 123 ); > } > > Such 'static' and 'inline' attributes do not make sense for a template, do > they? Or do they actually have an effect? > They definitely have an effect. Exactly the same effects as on non-templates. 'static' gives it internal linkage, so the function has a different identity in every object. 'inline' makes it an inline function, which increases the probability that GCC will choose to inline the function when optimizing. The 'inline' specifier also allows a function to be defined in multiple objects, without getting redefinition errors - that aspect of 'inline' is not needed for function templates, because they can always be defined in multiple objects. (Why are you using 'static inline' on the non-template functions in the first place? Why not just 'inline'?) > Is there a way to make GCC issue warnings about them? At the very least, > it would save some head scratching during code reviews. > > Thanks in advance, > rdiez >