1

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

Boppity Bop
  • 9,613
  • 13
  • 72
  • 151
  • 1
    You could disable the warning, `-Wno-unknown-pragmas` – Eljay Apr 04 '22 at 16:12
  • I dont want that either. I need to know if a "truly" unknown pragma appears in the code – Boppity Bop Apr 04 '22 at 16:16
  • 1
    Then you could wrap a `#pragma GCC diagnostic` *blah blah* around each `#pragma region` to disable the warning for the actually expected other-platform pragma. (I'm not sure if a region pragma can be replaced with the `__pragma(region)`, but if it can then the other platform could `#define __pragma(x)` to nothing.) – Eljay Apr 04 '22 at 16:18
  • I tried the first suggestion. didnt work. I edited the question – Boppity Bop Apr 04 '22 at 16:22
  • 1
    Looks like a GCC bug, consider reporting it. – HolyBlackCat Apr 04 '22 at 16:25
  • @Eljay - tried `__pragma` - it doesnt show a warning anymore. But VS doesnt recognise it as a `region` - I cant collapse it.. Ok neverming. Seems like a waste of time! – Boppity Bop Apr 04 '22 at 16:27
  • 2
    `#ifdef _MSC_VER` around each pragma may be a workaround for what appears to be a GCC bug. – Eljay Apr 04 '22 at 16:28
  • 2
    https://stackoverflow.com/questions/55069333/cannot-temporarily-disable-unknown-pragmas-warning-in-gcc – Paul Sanders Apr 04 '22 at 16:31
  • why I never find these things when I google?! :) – Boppity Bop Apr 04 '22 at 16:34
  • 1
    Also https://stackoverflow.com/questions/12842306/suppress-wunknown-pragmas-warning-in-gcc and https://stackoverflow.com/questions/31509434/gcc-does-not-honor-pragma-gcc-diagnostic-to-silence-warnings P.S. There is no such thing as standard pragma in C++. All pragmas are implementation defined. – eerorika Apr 04 '22 at 17:14

1 Answers1

1

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.

Mike of NZ
  • 26
  • 3