Questions tagged [compiler-warnings]

Messages emitted by a compiler which indicate potential problems in code or configuration.

Compiler warnings typically flag patterns in code that could potentially cause problems, but for lack of context the compiler cannot declare absolutely that the code is flawed.

2652 questions
72
votes
3 answers

Can I get PyCharm to suppress a particular warning on a single line?

PyCharm provides some helpful warnings on code style, conventions and logical gotchas. It also provides a notification if I try to commit code with warnings (or errors). Sometimes I consciously ignore these warnings for particular lines of code (for…
lofidevops
  • 15,528
  • 14
  • 79
  • 119
72
votes
4 answers

What does casting to `void` really do?

An often used statement like (void)x; allows to suppress warnings about unused variable x. But if I try compiling the following, I get some results I don't quite understand: int main() { int x; (short)x; (void)x; (int)x; } Compiling…
Ruslan
  • 18,162
  • 8
  • 67
  • 136
68
votes
7 answers

c array - warning: format not a string literal

I'm attempting to learn C and already I've run into an issue. I assume its trivial but I need to know it. I have written: #include #include int main() { char str_a[20]; strcpy(str_a, "Hello, world!\n"); …
bigl
  • 1,063
  • 3
  • 13
  • 23
67
votes
5 answers

Unnecessary @SuppressWarnings("unused")

I'm getting a compiler warning for the @SuppressWarnings annotation in eclipse for the code: @Override public boolean doSomething(@SuppressWarnings("unused") String whatever) throws AnException { throw new AnException("I'm still in bed and can't…
Edd
  • 8,402
  • 14
  • 47
  • 73
66
votes
8 answers

Using enum inside types - Compiler warning C4482 C++

I am using fully qualified name of the enum inside a method in one of my class. But I am getting compiler warning which says "warning C4482: nonstandard extension used: enum 'Foo' used in qualified name". In C++, do we need to use enums without the…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
65
votes
7 answers

Can GCC not complain about undefined references?

Under what situation is it possible for GCC to not throw an "undefined reference" link error message when trying to call made-up functions? For example, a situation in which this C code is compiled and linked by GCC: void function() { …
STenyaK
  • 1,047
  • 1
  • 8
  • 15
61
votes
3 answers

How to ignore compiler warning when using Obsolete attribute on a class used with a KnownType attribute

So we are trying to deprecate some of our existing classes, and have started marking them as obsolete with the ObsoleteAttribute so they will stop being used. The fact that using the KnownType attribute with a type that is marked with the Obsolete…
Jace Rhea
  • 4,982
  • 4
  • 36
  • 55
61
votes
8 answers

Avoid warning 'Unreferenced Formal Parameter'

I have a super class like this: class Parent { public: virtual void Function(int param); }; void Parent::Function(int param) { std::cout << param << std::endl; } ..and a sub-class like this: class Child : public Parent { public: void…
bdhar
  • 21,619
  • 17
  • 70
  • 86
61
votes
4 answers

Why does C++ code missing a formal argument name in a function definition compile without warnings?

While getting started with some VS2005-generated MFC code, I noticed it overrode a method with something like this: void OnDraw(CDC* /*pDC*/) { ... // TODO: Add your code here } So of course, as soon as I added something I realized I needed…
Andrew Coleson
  • 10,100
  • 8
  • 32
  • 30
60
votes
3 answers

C#: Is pragma warning restore needed?

From msdn I get this: #pragma warning disable warning-list #pragma warning restore warning-list In the examples, both disable and restore are used. Is it necessary to restore if I want it disabled for a whole file? Like, if I do not restore, how…
Svish
  • 152,914
  • 173
  • 462
  • 620
60
votes
9 answers

How can I suppress javac warnings about deprecated api?

When I compile, javac outputs: Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.` I wish to suppress this warning. Trying -Xlint:none does not seem to help.
IttayD
  • 28,271
  • 28
  • 124
  • 178
59
votes
3 answers

Compiler warning - suggest parentheses around assignment used as truth value

When I try to compile the piece of code below, I get this warning: warning: suggest parentheses around assignment used as truth value Why does this happen? This is a rather common idiom, I believe. I even use something like it earlier on my…
F. P.
  • 5,018
  • 10
  • 55
  • 80
59
votes
5 answers

C++ Force compile-time error/warning on implicit fall-through in switch

switch statements can be super useful, but lead to a common bug where a programmer forgot a break statement: switch(val) { case 0: foo(); break; case 1: bar(); // oops case 2: baz(); …
Barry
  • 286,269
  • 29
  • 621
  • 977
58
votes
9 answers

assert() with message

I saw somewhere assert used with a message in the following way: assert(("message", condition)); This seems to work great, except that gcc throws the following warning: warning: left-hand operand of comma expression has no effect How can I stop…
Alexandru
  • 25,070
  • 18
  • 69
  • 78
57
votes
6 answers

Multi-character constant warnings

Why is this a warning? I think there are many cases when is more clear to use multi-char int constants instead of "no meaning" numbers or instead of defining const variables with same value. When parsing wave/tiff/other file types is more clear to…
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211