Does the Sun compiler have a notation to mark functions as deprecated, like GCC's __attribute__ ((deprecated))
or MSVC's __declspec(deprecated)
?
views:
238answers:
2
+1
A:
This will get you a compiler warning on sun with the "+w" flag or on gcc with the "-Wall" flag. Unfortunately it breaks the ABI compatibility of the function; I haven't discovered a way around that yet.
#define DEPRECATED char=function_is_deprecated()
inline char function_is_deprecated()
{
return 65535;
}
void foo(int x, DEPRECATED)
{
}
int main()
{
foo(3);
return 0;
}
The output:
CC -o test test.cpp +w
"test.cpp", line 7: Warning: Conversion of "int" value to "char" causes truncation.
"test.cpp", line 15: Where: While instantiating "function_is_deprecated()".
"test.cpp", line 15: Where: Instantiated from non-template code.
1 Warning(s) detected.
The way you use it is when you want to declare a function deprecated, you add a comma to the end of its parameter list and write DEPRECATED. The way it works under the hood is it adds a default argument (thus preserving API) that causes the conversion warning.
Joseph Garvin
2009-05-21 17:15:09
Seems that the template argument <LINE> went missing somewhere.
MSalters
2009-05-22 09:23:13
I was thinking wrong about when the template argument would get evaluated so I got rid of it.
Joseph Garvin
2009-05-22 18:21:25
+1
A:
It seems that one solution that would work on any compiler that supports #warning
would be:
- Copy the header in question to a new, promoted header name
- Remove the deprecated functions from the promoted header file
- Add to the old header file:
#warning "This header is deprecated. Please use {new header name}"
Shmoopty
2009-06-02 01:07:34