Regarding compiling - __attribute__((deprecated))
LiLy
xmlymt@hotmail.com
Fri Aug 10 18:42:00 GMT 2012
Hi,
An attribute '__attribute__((deprecated))' can be used in a function declaration to indicate the function is deprecated.
I found some compiling issues as below and need your answers.
1. __declspec (deprecated) not supported in gcc 4.5.3. Perhaps also not supported by later releases.
__declspec (deprecated) is used by VS on windows, __attribute__((deprecated)) is the equivalent in gcc. While __declspec is the keyword in C/C++ standard, it seems the form of '__declspec (deprecated)' is more standard? Will gcc also support '__declspec (deprecated)' syntax in the future?
2. Cannot compile in some cases, can in similar cases
The error reads, 'error: attributes are not allowed on a function-definition'. Same to both normal member funtions and construcotr.
class A
{
public:
void func(int a , int b);
};
void A::func(int a, int b) __attribute__((deprecated))
{
}
Though I know __attribute__((deprecated)) should be used in function declaration other than definition, but following can compile and warning displays during compiling,
class A
{
public:
void func(int a , int b);
};
__attribute__((deprecated)) void A::func(int a, int b)
{
}
3. Used before non-inline constructor, can compile while no deprecated warning.
class A
{
public:
A(int i);
};
__attribute__((deprecated)) void A::A(int i)
{
}
At least gcc should report '__attribute__((deprecated)) will not take effect' in this case.
Thanks and Best Regards,
Xmly
More information about the Gcc-help
mailing list