I want to disable "Wmaybe-uninitialized" warning.
I use omnet++ ( base on c++ ) to simulate my project.
Is there anyway to disable this warning ?
I also found the following code , but it doesn't work.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#pragma GCC diagnostic pop
Adding the flag -Wno-maybe-uninitialized works, but should be used with care. See the thread GCC -Wuninitialized / -Wmaybe-uninitialized issues
Related
I'm using a GCC #pragma like this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
...
#pragma GCC diagnostic pop
This works great and removes the erroneous maybe-uninitialized errors that I'm seeing.
However, in old-ish versions of LLVM/clang++ (seen in clang version 9.0.0) this pragma is unknown and throws a warning. Since we also use -Werror, these warnings are turned to errors and compilation fails. See this output:
/home/path/to/include.hpp:22:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
^
In file included from /home/path/to/main.cpp:1:
/home/path/to/include.hpp:22:32: error: unknown warning group '-Wmaybe-uninitialized', ignored [-Werror,-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
^
1 error generated.
How can I use this GCC #pragma when compiling with LLVM?
I'm building some code with clang. Here's a cut-down version of what I'm doing. (Please bear in mind that during the cutting-down process, I've cut out every irrelevant detail I can, including anything that might make it obvious why I might actually want to do this.)
push.h:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragma-pack"
#pragma pack(push)
#pragma pack(1)
pop.h:
#pragma pack(pop)
#pragma GCC diagnostic pop
main.c:
#include "push.h"
struct Fred {char x;};
#include "pop.h"
Compile it like this:
clang -Wall -pedantic -c main.c
Doing this, I get a warning:
tmbp ~/tmp/pushpack % clang -Wall -pedantic -c main.c
main.c:3:10: warning: the current #pragma pack aligment value is modified in the included file [-Wpragma-pack]
#include "pop.h"
^
note: previous '#pragma pack' directive that modifies alignment is here
1 warning generated.
tmbp ~/tmp/pushpack %
How can I suppress this warning in this case? I'd like to do this by adding something to pop.h, if possible.
I don't really want to suppress the warning globally, because it seems like it might be kind of useful in the long run (even if not when I'm including push.h and pop.h).
I don't want to add additional junk to every include of pop.h, because in my non-cut-down actual program, because there's tons of them.
I don't want to have just a naked #pragma pack(pop) instead, because I'd prefer things to be symmetrical.
I don't want to make them symmetrical by inlining the contents of push.h, because in practice there's a bit more to it than is shown here.
What, if any, are my options?
Clang version: (this is the one that comes with Xcode 10 - don't think this warning was there in Xcode 9)
tmbp ~/tmp/pushpack % clang --version
Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
You cannot restore the warning options in pop.h if you don't want to see the warning generated for main.c resulting from including pop.h. Restore the warning options after `#include "pop.h".
I am trying to compile some nonconforming code in C++17, but I am stuck with the following issue.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-fpermissive"
Some code that compiles only when with -fpermissive flag is set:
#pragma GCC diagnostic pop
It compiles fine on GCC version 4.6.4 through 4.7.4, but all later versions of GCC are giving me the following warning and don't suppress the error.
warning: ‘-fpermissive’ is not an option that controls warnings [-Wpragmas]
#pragma GCC diagnostic ignored "-fpermissive"
When I write (out of desperation)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-fpermissive"
Some code that compiles only when with -fpermissive flag is set:
#pragma GCC diagnostic pop
I am back at square one. Currently I'd like to continue using GCC 7.1 for the project. I can compile the entire project with -fpermissive flag set as a compile option, but this means that some other section of code causing a -fpermissive error could compile.
Condensed example https://godbolt.org/g/KFd5Ke
This question is not a duplicate of In GCC, how can I mute the '-fpermissive' warning? as this is directed toward newer versions of GCC where the solution provided in the aforementioned Stack Overflow question does not work. I even included an example.
I am seeking for a way to suppress all possible warnings that i may get with Gcc with pragma directives. I had made some guard macros that help me silence 3rd party headers from warnings, and for now they work like charm for msvc and clang. I am still missing the correct way to use Gcc diagnostic pragmas in order to suppress every warning in a section. Let me give you some examples:
In msvc we can do this:
#pragma warning(push, 0)
// Code that produces warnings...
#pragma warning(pop)
And in clang we can do this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wextra"
// Code that produces warnings...
#pragma clang diagnostic pop
And the code that is in the middle is now being silenced from warnings for good.
And in Gcc we also have similar pragma directives with clang and i thought i could try something like this:
#pragma GCC diagnostic push
#pramga GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
// Code that produces warnings...
#pramga GCC diagnostic pop
But passing -Wall and -Wextra in diagnostic ignored pragma in GCC does not work like clang, and does not disable all the possible warnings. Instead of this passing a specific warning to disable works:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void foo (int x) // No longer getting "unused parameter 'x'" warning
{
}
#pragma GCC diagnostic pop
So the only workaround i can think so far is to make a long list with all the GCC warning flags and use them like above. Is there a more elegant solution?
If not where i can get the complete Gcc warning flag list (favorably in a plain list)?
Documentation says:
At the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.
I use Boost.Log v2 in one of my projects and I get the following warning when I build it:
C:\boost-1.55\include\boost\log\utility\setup\common_attributes.hpp:22: In file included from C:\boost-1.55\include/boost/log/utility/setup/common_attributes.hpp:22:0,
PROJECT_PATH\PROJECT_NAME\main.cpp:12: from ..\PROJECT_NAME\main.cpp:12:
C:\boost-1.55\include\boost\log\attributes\counter.hpp:-1: In instantiation of 'boost::log::v2_mt_nt5::attribute_value boost::log::v2_mt_nt5::attributes::counter<T>::impl_generic::get_value() [with T = unsigned int]':
PROJECT_PATH\PROJECT_NAME\main.cpp:44: required from here
C:\boost-1.55\include\boost\log\attributes\counter.hpp:133: avertissement : address requested for 'next', which is declared 'register' [-Wextra]
return make_attribute_value(next);
^
I'd like to remove this warning since I can't fix it as it's part of the Boost library. However, I did not find any -Wno-xxx option to remove it (-Wno-extra doesn't work). I'm using GCC 4.8.2.
How can I suppress this warning?
You may disable the warning when you include boost library
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra" // address requested for 'next', which is declared 'register'
//#include "boost/header_you_want.h"
#pragma GCC diagnostic pop