I just noticed that in my Arduino 1.8.19 IDE warnings were disabled on default. So I enabled to show all warnings and worked them through.
However there are some that I don't understand, don't care and the functionality is well tested. So I want to ignore some warnings from the C/CPP code.
Here is an example of an warning:
warning: declaration of 'enumType _enumType_::var' [-fpermissive]
enumType var : 3;
I would say that the compiler warns that it is not recommended to use an enum type in an bitfield. That's ok but it seems to work fine and it is much more readable with an enum, so I'm fine with it.
I tried with surrounding with:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
and
#pragma GCC diagnostic pop
which schould do the trick. However it does not work and I'm not sure about the options that are possible for -W???
Is there an explicit option for filtering an warning of that kind?
Where can I find a list of all filtering options?
Thanks.
In this case, this should suppress the warning:
#pragma GCC diagnostic ignored "-fpermissive"
There is quite some documentation here:
I tried that.
warning: '-fpermissive' is not an option that controls warnings [-Wpragmas]
#pragma GCC diagnostic ignored "-fpermissive"
^~~~~~~~~~~~~~
But I guess at least -Wall should work for filtering all warnings? It isn't in my case.
According to the documentation, -Wall
is not all. Maybe search for the word "enum" on that page?
Ok, thanks.
I did the test now the other way arround and added all warnings to be ignored, listed in https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
#pragma GCC diagnostic ignored "-Waddress"
#pragma GCC diagnostic ignored "-Warray-bounds=1"
#pragma GCC diagnostic ignored "-Warray-compare"
#pragma GCC diagnostic ignored "-Warray-parameter=2"
#pragma GCC diagnostic ignored "-Wbool-compare"
#pragma GCC diagnostic ignored "-Wbool-operation"
#pragma GCC diagnostic ignored "-Wc++11-compat"
#pragma GCC diagnostic ignored "-Wcatch-value"
#pragma GCC diagnostic ignored "-Wchar-subscripts"
#pragma GCC diagnostic ignored "-Wcomment"
#pragma GCC diagnostic ignored "-Wdangling-pointer=2"
#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"
#pragma GCC diagnostic ignored "-Wenum-compare"
#pragma GCC diagnostic ignored "-Wenum-int-mismatch"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-overflow"
#pragma GCC diagnostic ignored "-Wformat-truncation"
#pragma GCC diagnostic ignored "-Wint-in-bool-context"
#pragma GCC diagnostic ignored "-Wimplicit"
#pragma GCC diagnostic ignored "-Wimplicit-int"
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Winit-self"
#pragma GCC diagnostic ignored "-Wlogical-not-parentheses"
#pragma GCC diagnostic ignored "-Wmain"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wmemset-elt-size"
#pragma GCC diagnostic ignored "-Wmemset-transposed-args"
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#pragma GCC diagnostic ignored "-Wmismatched-dealloc"
#pragma GCC diagnostic ignored "-Wmismatched-new-delete"
#pragma GCC diagnostic ignored "-Wmissing-attributes"
#pragma GCC diagnostic ignored "-Wmissing-braces"
#pragma GCC diagnostic ignored "-Wmultistatement-macros"
#pragma GCC diagnostic ignored "-Wnarrowing"
#pragma GCC diagnostic ignored "-Wnonnull"
#pragma GCC diagnostic ignored "-Wnonnull-compare"
#pragma GCC diagnostic ignored "-Wopenmp-simd"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wpessimizing-move"
#pragma GCC diagnostic ignored "-Wpointer-sign"
#pragma GCC diagnostic ignored "-Wrange-loop-construct"
#pragma GCC diagnostic ignored "-Wreorder"
#pragma GCC diagnostic ignored "-Wrestrict"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wsequence-point"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsizeof-array-div"
#pragma GCC diagnostic ignored "-Wsizeof-pointer-div"
#pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#pragma GCC diagnostic ignored "-Wstrict-overflow=1"
#pragma GCC diagnostic ignored "-Wswitch"
#pragma GCC diagnostic ignored "-Wtautological-compare"
#pragma GCC diagnostic ignored "-Wtrigraphs"
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wunused-value"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wuse-after-free=3"
#pragma GCC diagnostic ignored "-Wvla-parameter"
#pragma GCC diagnostic ignored "-Wvolatile-register-var"
#pragma GCC diagnostic ignored "-Wzero-length-bounds"
#pragma GCC diagnostic ignored "-Wclobbered"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wenum-conversion"
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough=3"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wmissing-parameter-type"
#pragma GCC diagnostic ignored "-Wold-style-declaration"
#pragma GCC diagnostic ignored "-Woverride-init"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wstring-compare"
#pragma GCC diagnostic ignored "-Wredundant-move"
#pragma GCC diagnostic ignored "-Wtype-limits"
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wshift-negative-value"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
The original warning still appears and additionally many of the -W statements seem to be unknown. Strange...
Is there any other way to globally disable all warnings for a defined number of code lines?
When I configure the Arduino IDE to "Compiler warnings:" "None" then the warnings disappear. But that seems too risky for me to globally turn off warnings for the entire code.
I have no idea how the IDE does that, maybe it simply discards this compiler output.
At this point I would probably fix the code.
in0
May 27, 2022, 7:34pm
9
It simply defines a build property named compiler.warning_flags
which can be used (or not used) according to the preference of each boards platform author, but it typically looks something like this:
https://github.com/arduino/ArduinoCore-avr/blob/1.8.5/platform.txt#L14-L18
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
So when you select "none " in the Arduino IDE's File > Preferences > Compiler warnings preference, the build system sets the compiler.warning_flags
property to -w
.
That property is then used in the generation of the compilation commands. For example, you can see it here in the C++ file compilation command pattern:
https://github.com/arduino/ArduinoCore-avr/blob/1.8.5/platform.txt#L58
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
So it runs avr-g++
with the -w
flag that turns off warnings
Thank you for the replys.
It's not ideal but for now I changed my code to not use enum types inside a bitfield.
As said, technically it would work without any problem and speaking of coding style I find it much better to use enums instead of an int with defines.
But there seems to be no way to supress this warning only and setting the warning level to "None" is just a no go.
If someone finds a solution then please let me know.
Thank you for clearing this up.
Only -w
seems to suppress this warning using the command line, and this option can not be set using a #pragma
directive. Maybe there are other ways to accomplish this, but I do not know of any.
westfw
May 29, 2022, 10:18pm
12
Can you post a full piece of the offending code? I'm having a bit of trouble figuring out exactly what the complaint is.
I believe that avr-gcc has some hacks to allow an enum to be of slightly variable size (shortened from 16bit to 8bit if possible), that may be the root of your problem
system
Closed
November 25, 2022, 10:18pm
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.