Intel C++ compiler ignores attribute noinline

Submit New Article

Last Modified On :   June 15, 2009 2:23 AM PDT
Rate
 



Reference Number :  U66234


Version :  11.0


Operating System : 

Linux

Problem Description :
 

The Intel C++ compiler does not seem to work for no inline attribute. We get undefined symbol error during linking. The following is test case:

$ cat foo.hpp

template<class T>
class foo
{
public:
void mem();
};


$ cat foo.cpp
#include "foo.hpp"


template<class T> __attribute__((noinline))
void foo<T>::mem()
{

}

__attribute__((noinline))
void instantiatehelper()
{
foo<int> f;
f.mem();
}

]$ cat main.cpp
#include <iostream>
#include "foo.hpp"

int main()
{
foo<int> f;
f.mem();
std::cout << "main" << std::endl;
return 0;
}

$ icc main.cpp foo.cpp
/tmp/iccc84zBg.o: In function `main':
main.cpp:(.text+0x2e): undefined reference to `foo<int>::mem()'


Resolution Status : 

The problem appears to be that the Intel compiler is ignoring the attribute if it is only on the definition.

If you put the attribute on the declaration then the example links as expected ,i.e.:
template<class T>
class foo
{
public:
__attribute__((noinline)) void mem();
};







[DISCLAIMER: The information on this web site is intended for hardware system manufacturers and software developers. Intel does not warrant the accuracy, completeness or utility of any information on this site. Intel may make changes to the information or the site at any time without notice. Intel makes no commitment to update the information at this site. ALL INFORMATION PROVIDED ON THIS WEBSITE IS PROVIDED "as is" without any express, implied, or statutory warranty of any kind including but not limited to warranties of merchantability, non-infringement of intellectual property, or fitness for any particular purpose. Independent companies manufacture the third-party products that are mentioned on this site. Intel is not responsible for the quality or performance of third-party products and makes no representation or warranty regarding such products. The third-party supplier remains solely responsible for the design, manufacture, sale and functionality of its products. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. *Other names and brands may be claimed as the property of others.]




This article applies to: Intel® C++ Compiler for Linux* Knowledge Base,   Intel® C++ Compiler for Mac OS X* Knowledge Base