[cfe-dev] Possible incompatible gcc attribute parsing with GCC
Xiaolong Tang
xiaolong.snake at gmail.com
Wed Jun 29 14:32:17 PDT 2011
Hi all,
I am trying to see how far clang supports GNU attributes. It seems to
me that clang does not support declare attributes for members of
templates. Following is what I found:
I use a very simple test code (in template_attribute.cpp):
template<typename T> class vector {
private:
T rep[10];
public:
T top() { return rep[0]; }
};
template<typename T> T vector<T>::top() __attribute__ ((pure));
int main()
{
vector<int> a;
int r = a.top();
int t = a.top();
return r + t;
}
With this command:
g++ -O2 -cse -fno-inline -fdump-tree-all-all template_attribute.cpp
the above code gets compiled and optimized (CSE works here).
However, trying to compile the code with clang generates the following
message:
16:15:55->clang++ -c template_attribute.cpp
template_attribute.cpp:9:35: error: out-of-line declaration of a member must be
a definition [-Wout-of-line-declaration]
template<typename T> T vector<T>::top() __attribute__ ((pure));
~~~~~~~~~~~^
template_attribute.cpp:9:35: warning: attribute declaration must precede
definition
template_attribute.cpp:5:5: note: previous definition is here
T top() { return rep[0]; }
^
1 warning and 1 error generated.
PS: clang version 2.9 (trunk 126848)
Best,
Xiaolong
More information about the cfe-dev
mailing list