Clang: Replacing __attribute((__warning__())) by __attribute__((deprecated()))

Olivier MARTIN olivier@labapart.com
Sun Oct 25 18:40:00 GMT 2015


Clang does not support the function attribute __warning__(), it raises 
the warning message: "warning: unknown attribute '__warning__' ignored"
A solution would be to replace the attribute __warning__() by 
deprecated().

Here is the GCC & Clang behaviour with some function attributes:

# The source code:
----------------------------
void func1(void) __attribute__((__warning__ ("the use of `func1' is 
dangerous; use `funcN' instead")));
void func2(void) __attribute__((deprecated("Deprecated func2; use 
`funcN` instead")));
void func3(void) __attribute__((warning("the use of `func3' is 
dangerous; use `funcN' instead")));

int main(void) {
   func1();
   func2();
   func3();
   return 0;
}
---------------------------

# With GCC:
---------------------------
mytest.c: In function ‘main’:
mytest.c:7:3: warning: ‘func2’ is deprecated (declared at mytest.c:2): 
Deprecated func2; use `funcN` instead [-Wdeprecated-declarations]
    func2();
    ^
mytest.c:6:8: warning: call to ‘func1’ declared with attribute warning: 
the use of `func1' is dangerous; use `funcN' instead [enabled by 
default]
    func1();
         ^
mytest.c:8:8: warning: call to ‘func3’ declared with attribute warning: 
the use of `func3' is dangerous; use `funcN' instead [enabled by 
default]
    func3();
---------------------------

# With Clang:
---------------------------
mytest.c:1:33: warning: unknown attribute '__warning__' ignored 
[-Wunknown-attributes]
void func1(void) __attribute__((__warning__ ("the use of `func1' is 
dangerous; use `funcN' instead")));
                                 ^
mytest.c:3:33: warning: unknown attribute 'warning' ignored 
[-Wunknown-attributes]
void func3(void) __attribute__((warning("the use of `func3' is 
dangerous; use `funcN' instead")));
                                 ^
mytest.c:7:3: warning: 'func2' is deprecated: Deprecated func2; use 
`funcN` instead [-Wdeprecated-declarations]
   func2();
   ^
mytest.c:2:6: note: 'func2' has been explicitly marked deprecated here
void func2(void) __attribute__((deprecated("Deprecated func2; use 
`funcN` instead")));
      ^
3 warnings generated.
---------------------------

Here is the list of the function attributes supported by clang:
- http://clang.llvm.org/docs/LanguageExtensions.html
- http://clang.llvm.org/docs/AttributeReference.html

Are you happy by my suggestion of replacing __attribute((__warning__())) 
by __attribute__((deprecated()))?
I am happy to send a patch if needed.
Thanks,

-- 
Olivier MARTIN
http://labapart.com



More information about the Newlib mailing list