How to disable narrowing conversion warnings? - c++

I use -Wall and updating to new gcc I have got a lot of warning: narrowing conversion. I want to disable them, but leave all other warnings untouched (ideally).
I can find nothing about narrowing in http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
How to disable narrowing conversion warnings?
Is it possible at all?
P.S.
I need to Disable warnings, not fix them in the source code.
Blind -Wno-conversion doesn't help.

As gx_ said, adding -Wno-narrowing to your command line should ignore those errors. Encountered this myself when upgrading to C++0x.

As a small FYI, as detailed on https://clang.llvm.org/docs/DiagnosticsReference.html#wnarrowing this is an alias for -Wno-c++11-narrowing (there are multiple narrowing warning flags)

Related

Fortran pause function not working in Force 2.0 [duplicate]

I googled it but i could not find the answer. How can I suppress this warning AND ONLY THIS:
Warning: Deleted feature: PAUSE statement at (1)
i know I can supress all the warning but I wanna suppress only this one. Or if not possible. suppress warning for delete features.
thanks
A.
Compile with -std=legacy or -w (lowercase). Note that -w will suppress all warnings.

GCC vs Clang: Meaning of "-pedantic-errors"

I'm using Clang v3.7.0 with Mingw-w64 5.1.0 and GCC 5.1.0, all 64-bit, on Windows 10. My goal is to use a set of Clang and GCC options that will give me the best chance of detecting potential C89 and C++98 language standards portability issues across many different compilers. For example, for C I have been using the following GCC command line with pretty good success:
gcc -c -x c -std=c89 -pedantic-errors -Wall -Wextra -Wno-comment -Wno-parentheses -Wno-format-zero-length test.c
However, I recently tried it with Clang and got a different result. Here is my sample test code:
int main(void)
{
int length = (int)strlen("Hello");
return 0;
}
With Clang I get the following error, whereas with GCC I get the same basic thing, but it flags it as a warning instead:
test.c:3:22: error: implicitly declaring library function 'strlen'
with type 'unsigned long long (const char *)'
int length = (int)strlen("Hello");
If I remove the -pedantic-errors option, or just change it to -pedantic, Clang then only flags it as a warning, which is what I actually want. However, according to the GCC documentation the -pedantic-errors option causes warnings that are considered language extensions to be flagged as errors, but not using a prototype for a function is not an extension in C89. So, I have three basic questions:
Has Clang changed the meaning of -pedantic-errors from the meaning used by GCC, or am I misinterpreting something?
What is the best set of options that will enforce adherence to the selected standard and will issue errors for all non-conforming code?
If I continue to use -pedantic-errors with Clang is there a way to get it to issue a warning instead of an error in specific cases? In another posting on this site an answer was given that said to use the following, where foo is the error:
-Wno-error=foo
If that is a correct approach, what do I actually use in place of foo for an error like I'm getting since there is no actual error number indicated? I can't believe it actually wants all of the following:
-Wno-error=implicitly declaring library function 'strlen'
with type 'unsigned long long (const char *)'
Your code is invalid, and the behavior is undefined, so the compiler can do anything also when compiling. The implicitly declared int strlen(char*) is not compatible with size_t strlen(const char *).
Has Clang changed the meaning of -pedantic-errors from the meaning used by GCC, or am I misinterpreting something?
As I read it, yes. From clang documentation:
-pedantic-errors
Error on language extensions.
In GCC:
-pedantic
Issue all the warnings demanded by strict ISO C and ISO C++ [...]
-pedantic-errors
Give an error whenever the base standard (see -Wpedantic) requires a diagnostic, in some cases where there is undefined behavior at compile-time and in some other cases that do not prevent compilation of programs that are valid according to the standard.
Clang errors on extensions.
GCC errors when standard explicitly requires it and in other "some cases".
This is a different, it is a different set of errors. Standard may not require a diagnostic, but it's still an extension - GCC will be silent, Clang will error.
What is the best set of options that will enforce adherence to the selected standard and will issue errors for all non-conforming code?
The first answer that comes to mind is: "none". Compiler inherently use "implementation-defined behavior" and extension, because they are meant to compile the code in the first place, not meant to not compile non-conforming code. There are cases where the code is conforming, but still the behavior differs between compilers - you can explore such a case here.
Anyway, keep using -pedantic-errors, as it seems to work in detection of non-conforming code. Your code is invalid, the behavior is undefined, so your code is non-conforming, so clang properly detects it. Also use linters and sanitizers to detect other cases of undefined behavior.
If I continue to use -pedantic-errors with Clang is there a way to get it to issue a warning instead of an error in specific cases?
Use -fno-builtin.

suppress gfortran warning message

Does anyone know if there is an option to suppress the following warning message
from gfortran:
Warning: Extension: Conversion from HOLLERITH to INTEGER(4) at (1)
(Without changing the code, that is).
I have already tried the options: -Wno-conversion-extra -Wno-conversion
I'm using gfortran 4.9.1 by the way.
Probably you can try this way:
-std=legacy
This may suppress the warning information as you mentioned since Hollerith constant is the legacy feature before FORTRAN77. However, downside of using this option is that all the possible legacy collision may not be shown. I have tested this option on gfortran 6.2.0.

Silence the warning: `Non-conforming tab character` in gfortran

I usually run my code with ifort, but during implementation, I prefer compiling and testing with gfortran as I find it to be a lot stricter than its intel counterpart.
While turning on compiling options such as -Wall, I get the following warning:
Warning: Nonconforming tab character at (1)
Is there a way to silence this one particular warning while using the same compiling options? Note that I do NOT want to replace tabs with space characters. If there is no way to resolve this issue, then the answer "No it's not possible" would suffice.
Warning: the below answer I originally wrote only applies to gfortran 4.x. The behaviour has been reversed in version 5.x, see the answer by DrOli.
What have you tried so far? Does -Wtabs help? From man gfortran:
-Wtabs
By default, tabs are accepted as whitespace, but tabs are not members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported. -Wno-tabs
will cause a warning to be issued if a tab is encountered. Note, -Wno-tabs is active for -pedantic, -std=f95, -std=f2003, -std=f2008 and -Wall.
And -Wall sets -Wno-tabs.
If it doesn't help, it could still be that -Wall overwrites this option. Then you can try manually setting -Wall without the tabs part:
-Wall
Enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes -Waliasing, -Wampersand, -Wconversion,
-Wsurprising, -Wc-binding-type, -Wintrinsics-std, -Wno-tabs, -Wintrinsic-shadow, -Wline-truncation, -Wtarget-lifetime, -Wreal-q-constant and -Wunused.
UPDATE: With GCC/gFortran 5xx (I noticed with 5.3.0), the -Wtabs usage has been "reversed", and as they say, "made more sensible".
See here (https://gcc.gnu.org/gcc-5/changes.html)
Now -Wtabs DOES give the nonconforming warning, whereas -Wno-tabs TURNS OFF the warning (i.e. the opposite of the previous usage).
The easiest way of getting rid of the warning in gfortran versions 4.x is to overwrite the -Wno-tabs flag that the -Wall flag sets. So first include -Wall and then -Wtabs
-Wall -Wtabs

Making the 'delete' warnings in GCC into errors

I want to make the following warnings in GCC into errors, however, I failed to find any documentation on which switches control them, including the -fdiagnostics-show-option switch.
The warnings are:
deleteing void * is undefined
and
possible problem detected in invocation of delete operator:
'p' has incomplete type
I only want to make the specified warnings into errors, not all of them.
The [enabled by default] part of the warnings (that you didn't show) indicates that there isn't any specific warning flag controlling them, so there isn't anything you can use to say -Wno-xxx or -Werror=xxx.
With GCC 4.9 you can use -Werror=delete-incomplete to control the second one.
You can compile with the -Werror tag to treat warnings as errors.