Search code examples
c++linuxg++pragma

g++ complains of #pragma region if I use #pragma GCC diagnostic


I need to disable warning in an include file.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
<some function>
#pragma GCC diagnostic pop

however in the main.cpp file which includes the above .h file I use

#pragma region class_definitions

I know it is "not standard pragma" - I use it to control huge amount of declarations in the main file as I use VS for editing code, before I go to linux

So I get this warning (which does NOT appear if I dont use #pragma GCC diagnostic push/pop)

warning: ignoring ‘#pragma region class_definitions’ [-Wunknown-pragmas]

Is there a way to have a cake AND eat it?

EDIT: I tried this and the warning still shows

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma region class_definitions
#pragma GCC diagnostic pop


Solution

  • I have faked #pragma region as follows.

    #ifndef __PRAGMAREGION__ // Sign commands
    ... code goes here ...
    #endif // Sign commands
    

    VSCode does collapse/expand in the same way as #pragma region; and the GCC compiler is fine with it.

    Not perfect... but the VSCode collapse feature is too important to lose.