Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable GCC warning "Wstack-usage" temporarily?

I am trying to compile a project that imports this BiTStream file.

GCC outputs the following error:

warning: stack usage might be unbounded [-Wstack-usage=]

Indeed, in the compilation command line (generated via CMake) I have:

-Wstack-usage=2048

I want to keep this warning for the rest of the project but disable it for this specific file.

I have checked GCC Warnings options and GCC diagnostic pragmas and tried:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wswitch-default"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wstack-usage"

#include <bitstream/mpeg/psi/descs_print.h>

#pragma GCC diagnostic pop

But GCC still complains:

warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

#pragma GCC diagnostic warning "-Wstack-usage"

Note that the other warnings are correctly disabled.

Is there a specific synatx for Wstack-usage ?

like image 783
n0p Avatar asked Feb 24 '16 15:02

n0p


People also ask

How do I turn off GCC warnings?

The warning message for each controllable warning includes the option that controls the warning. That option can then be used with -Werror= and -Wno-error= as described above. (Printing of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)

How do I turn off error warning?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).

How do I ignore a warning in Makefile?

Maybe you can look for CFLAGS options in Makefile and remove the -Werror flag. The Werror flag will make all warnings into errors.

How does GCC treat warning errors?

You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.


1 Answers

The clue is in the error message:

warning: stack usage might be unbounded [-Wstack-usage=]

Thus, the #pragma you need to use is:

#pragma GCC diagnostic ignored "-Wstack-usage="
like image 61
jpa Avatar answered Sep 23 '22 19:09

jpa