Hi,
I'm writing a numerical c++ library and would like to support GCC
version >= 3.4.4. For performance reasons I absolutely require the
inlining of certain templated helper functions, but this seems to be a
problem with GCC prior to version 4.0 under certain circumstances
because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14950
For example, the following code will not compile with "-g":
--
#include <iostream>
template <int size>
inline __attribute__((always_inline)) int shift(int val) {
return val << size;
}
int main() {
std::cout << shift<2>(1); // "sorry unimplemented: inlining failed"
}
--
It actually does compile with "-O1" but I've got more complicated code
where the inlining fails in a similar situation even though I'm
compiling with optimizations switched on.
Now I'm having difficulties understanding when exactly this bug is
triggered. Could maybe someone explain to me under which circumstances
GCC 3.4 fails to inline a templated function? Are there any general
workarounds? Is there any chance that the compiler inlines code even
though always_inline fails?
Thanks in advance for any hint.
Stephan