vendredi 6 avril 2018

How to use _Pragma operator in macro?

I'm trying to use the _Pragma operator in order to ignore a warning inside a macro:

#define RAII_BLOCK() \
    _Pragma("GCC diagnostic push \"-Wshadow\"") \
    _Pragma("GCC diagnostic ignored \"-Wshadow\"") \
    auto a = RAII(); \
    _Pragma("GCC diagnostic pop")

void foo() {
    RAII_BLOCK();
    {
        RAII_BLOCK();    
    }
}

But I see really odd behavior from gcc. If RAII_BLOCK is a macro with no arguments it works as expected: https://godbolt.org/g/J6RxDV

But if I add the parenthesis (in my use case I actually need to pass a real argument), gcc starts complaining: https://godbolt.org/g/tbNtje

Note that clang works as expected in both cases. Does anyone know how to get around this issue (while keeping the shadow warnings for the rest of the code)?

Aucun commentaire:

Enregistrer un commentaire