c++gccconditional-compilationgcc-pedantic

Is it possible to use GNU extensions unless pedantic?


Is there a way to conditionally enable features that rely on GCC extensions (such as __int128) if they would compile?

I want to do something like

void foo(int);
void foo(long);
void foo(long long);
#if not_pedantic
void foo(__int128);
#endif

I could not find a macro that is defined when -pedantic or pedantic-error is passed.


Solution

  • This is a bad idea. Only check the compiler, and disable the -pedantic-errors warnings with #pragmas or __extension__:

    void foo(int);
    void foo(long);
    void foo(long long);
    #ifdef __GNUC__
    __extension__ void foo(__int128);
    #endif
    

    If your user builds with -pedantic-errors but still uses the extensions as needed, they would be very annoyed if you disable overloads like this.