Re: How to issue a warning if a C++ template is defined as 'inline' or 'static'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




First of all, thanks for your quick answer.

[...]
(Why are you using 'static inline' on the non-template functions
in the first place? Why not just 'inline'?)

Actually, I am not. I normally use 'inline' in headers and 'static' in .cpp files. I just wanted to simplify the example, but I shouldn't have.

I'll rephrase the takeaway, to check whether I understood this correctly:

- 'inline' just makes the template function more likely to be inlined, but it is not required in a header file, like it is usually required for normal functions in order to prevent redefinition errors.

- 'static' has the same effect for templates as for normal functions, and can be problematic in header files, especially if the template or function has static variables inside.

Incidentally, I wonder how the linker detects and merges duplicate templates, or even duplicate normal inline functions. The template or inline function could have different bodies in different compilation units. A simplified example would be:

file1.cpp:

inline int test ( void )
{ return 1; }

file2.cpp:

inline int test ( void )
{ return 99999; }

I read somewhere that the standard does not require detecting the above problem. Will GCC or the linker detect this problematic case?

Regards,
  rdiez




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux