Get list of default GCC warnings - gcc

I'd like to know if it's possible to get a list of warnings that are enabled in GCC when no -Wx or -W-no-x flags are specified? I need this because I've got 2 different GCC versions (namely 3.3 and 4.3) which react differently on the same code with the same compilation flags.
For example, 4.3 with no additional warning options throws a warning when signed-to-unsigned comparison occurs while 3.3 does only if -Wsign-compare flag. So, I'd like to figure out, which flags should I add to gcc-3.3 to force it to detect the same warnings 4.3 does by default.
For 4.3 I'd managed to get such list of warnings using gcc -Q --help=warnings | grep enabled, but 3.3 doesn't seems to provide such function. Does anybody know, how it can be done in any other way? Maybe the source file that defines warning states?
Regards,
Marvin

GCC command line options are usually defined in gcc/common.opt file.
Try searching for `Warning' keyword in this file.

Related

How to configure clang to use arm-none-eabi linker

I am trying to configure the last version of clang (6.0) to use the arm-none-eabi linker instead of the ld.lld but clang is always ignoring everything and keep asking for the ld.lld one. I am trying to build for cortex-m3 (lpx1769 board). How do I force clang to use the linker I want.
-fuse-ld=ld is also not working, so does clang no longer allow the use of any other linker?
So the answer was to use the flag:
-fuse-ld=path/to/linker-to-be-used
Remember that if you passing this flag to clang it will cause a warning that clang will not use this flag (only the linker stage will do). Thus if you compiling with -Werror, the warning will be turned into an error.
Moreover, because you are cross-compiling probably you will need to let the linker know where to find the target-specific libraries needed using the -L option. See this for more info:
https://clang.llvm.org/docs/CrossCompilation.html

How do I pass -mfpmath=sse to LLVM using CLANG

I am trying to compile a number of GNU tools on Mac OS X [10.8.5]. One of the optimization options I was able to use in the past is '-mfpmath=sse', but now I get the message:
clang: warning: argument unused during compilation: '-mfpmath=sse'
Now, llvm-gcc help says it supports '-mfpmath=sse', and clang has a method of passing things to llvm using '-mllvm ', but I cannot seem to make them work together.
Are these two options even meant to work together? If so, how?
What if I want to pass multiple LLVM arguments from CLANG using '-mllvm '? Is that possible, and if so, how?
Thanks,
Nick
You do not need this flag with clang. It defaults to "-mfpmath=sse" as soon as your processor does support it.
If you need to pass multiple options to LLVM directly (though, it seems to be pretty bad idea - you do not need to do so), you can just -mllvm multiple times, e.g. "-mllvm -foo -mllvm -bar".

build fail with gcc4.6 but not with gcc4.5

we here use -Werror=unused-but-set-variable gcc compiler option while building our code. Apparently the people using gcc4.5 can build it "even though" there are variables which are set but not used afterwards. But I using gcc4.6 cannot build the code. Is that particular gcc option not implemented in gcc4.5?
thanks in advance
The GCC 4.6 warnings are improved w.r.t. to those produced by GCC 4.5. But you could just use -Wunused-but-set-variable to get warnings, not errors, and more importantly correct your source code (perhaps by removing that useless variable).

gcc and clang warnings/errors flags

Where can I find a list of all available warning and error flags I can set in clang and gcc? I've looked all over both of their respective documentation sites, and I can't find anything.
gcc --help=warnings,seperate
gcc --help=warnings,joined
gcc --help=warnings,undocumented
gcc --help=warnings
seperate flags are like boolean values; they are either on or off.
-Wflag means on. -Wno-flag means off.
joined flags are flags that require a value.
-Wflag=value
by typing gcc --help=warnings you will recieve all the warning options provided by your compiler.
EDIT:
looking at GNU Documentation, these warnings messages have existed since GCC 4.3.6
GCC: http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html#Option-Summary.
For Clang, there is -Weverything, which enables all warning flags.
The classic: man gcc. clang's manpage is not that populated yet, but since it mimics gcc's behavior anyway, many of gcc's -W options also work with clang.
If the question is just to find the list of all possible GCC diagnostic (error, warning, ...) messages, you could use the catalog of messages for localization utilities. With the GCC source tar ball, look inside gcc/po/ or libcpp/po/ or libstdc++-v3/po/ etc.
If you just ask about the options used to get these messages, follow the link in the answer by Oli Charlesworth

How can I make this GCC warning an error?

I get this warning from GCC:
warning: cannot pass objects of non-POD type 'class Something' through '...'; call will abort at runtime
It's pretty deadly, especially since it calls an abort. Why isn't this an error? I would like to make it an error, but:
How do I make a specific warning an error?
Which warning is it? According to 3.8 Options to Request or Suppress Warnings, -Wno-invalid-offsetof, it looks like the flag to hide it, but it doesn't.
I'm not sure what the correct warning is, but once you've found it, you can change its disposition with the following (using 'format' as the example):
#pragma GCC diagnostic error "-Wformat"
Or as strager points out:
gcc -Werror=format ...
I've checked the gcc source for this and this specific warning cannot be disabled via command line flags.
-Werror=specific-warning will turn the specified -Wspecific-warning into an error in GCC 4.3.x or newer. In 4.1.2, only -Werror-implicit-function-declaration works. Note the hyphen instead of equals sign -- it works for that specific case only and no others. This is one of the more serious common warnings and it's definitely handy to make it into an error.
Apart from that, older versions of GCC only seem to provide the -Werror sledgehammer of making every last warning an error.
It sounds like there are a bunch of other warnings that you don't want to be turned into errors (using the -Werror flag). In general, it's good practice to fix all warnings. Using -Werror forces this.
You can use the -Werror compiler flag to turn all or some warnings into errors.
You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.
Unfortunately, in this case there isn't any specific option that covers that warning.
It appears that there will be better support for this in GCC 4.5.

Resources