Detecting the 'deprecated' attribute and -Wno-system-headers

Ben Davis bnd25@cam.ac.uk
Thu Jan 23 02:09:00 GMT 2003


Hi,

I have a project in which I detect the GCC version and generate some compiler 
flags accordingly before compiling the project itself. The existing code for 
the detection is as follows:

#if __GNUC__ >= 3
    /* Use __attribute__((__deprecated__)) and -Wno-system-headers */
#else
    /* - Anally refuse to declare the functions unless a certain symbol
     *   is defined to override this >:) and output a flag to declare
     *   the symbol for the library build
     * - -Wno-system-headers doesn't exist, and a header from another
     *   library doesn't like my strict warning selection, so disable
     *   some of them
     */
#endif

GCC 3.1 and 2.x are happy. Unfortunately GCC 3.0.3 doesn't seem to support 
the 'deprecated' attribute, and I get a sea of warnings resembling the 
following:

foo.h:666: warning: `__deprecated__' attribute directive ignored

There are a couple of different ways I could solve this problem, but I'll 
need some help...

- If there's a warning flag the suppresses the 'attribute ignored' warnings, 
I could add this to the flags I use. Unfortunately '-w' is the only warning 
I've found that actually does this. Does anyone know if there is a specific 
flag for this warning? But this solution is not ideal, as it will result in 
people being able to use the deprecated APIs without realising they're 
deprecated...

- Does anyone know which GCC version (between 3.0.3 and 3.1) the 'deprecated' 
attribute was introduced in? If you have version 3.0.4, perhaps you could try 
compiling a file with the following in it:

int yay(void) __attribute__((deprecated));
int main(void) { return yay(); }

There is a second problem with this though. As far as I know, __GNUC__ only 
contains the main version number (2 or 3 in general). How do I detect the 
other parts of the version?

- Does MSVC have a security hole whereby I can cause GCC to be downloaded on 
to the user's system? j/k :)

As for -Wno-system-headers, I haven't had any problems yet. But can anyone 
confirm that the flag does exist in GCC 3.0.0?

Thanks in advance

Ben



More information about the Gcc-help mailing list