3

Does the Sun compiler have a notation to mark functions as deprecated, like GCC's __attribute__ ((deprecated)) or MSVC's __declspec(deprecated)?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180

2 Answers2

2

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}"
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
1

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
  • 20,727
  • 18
  • 94
  • 165