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
484
votes
12 answers

How to disable unused code warnings in Rust?

struct SemanticDirection; fn main() {} warning: struct is never used: `SemanticDirection` --> src/main.rs:1:1 | 1 | struct SemanticDirection; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default I will turn these…
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
349
votes
21 answers

Why should I always enable compiler warnings?

I often hear that when compiling C and C++ programs I should "always enable compiler warnings". Why is this necessary? How do I do that? Sometimes I also hear that I should "treat warnings as errors". Should I? How do I do that?
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
321
votes
9 answers

What is the list of valid @SuppressWarnings warning names in Java?

What is the list of valid @SuppressWarnings warning names in Java? The bit that comes in between the ("") in @SuppressWarnings("").
Ron Tuffin
  • 53,859
  • 24
  • 66
  • 78
310
votes
9 answers

How to disable GCC warnings for a few lines of code

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
295
votes
5 answers

What is "android:allowBackup"?

Since the new ADT preview version (version 21), they have a new lint warning that tells me the next thing on the manifest file (in the application tag): Should explicitly set android:allowBackup to true or false (it's true by default, and that can…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
286
votes
10 answers

Message "warning: implicit declaration of function"

My compiler (GCC) is giving me the warning: warning: implicit declaration of function Why is it coming?
Angus
  • 12,133
  • 29
  • 96
  • 151
254
votes
8 answers

How can I turn on (literally) ALL of GCC's warnings?

I would like to enable—literally—all of the warnings that GCC has. (You'd think it would be easy...) You'd think -Wall might do the trick, but nope! You still need -Wextra. You'd think -Wextra might do the trick, but nope! Not all of the warnings…
user541686
  • 205,094
  • 128
  • 528
  • 886
221
votes
11 answers

Property getters and setters

With this simple class I am getting the compiler warning Attempting to modify/access x within its own setter/getter and when I use it like this: var p: point = Point() p.x = 12 I get an EXC_BAD_ACCESS. How can I do this without explicit backing…
Atomix
  • 13,427
  • 9
  • 38
  • 46
194
votes
4 answers

Objective-C implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int' warning

I'm working through some exercises and have got a warning that states: Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int' #import int main (int argc, const char * argv[]) { …
monkeyboy
  • 1,961
  • 2
  • 13
  • 7
181
votes
6 answers

What's the point of g++ -Wreorder?

The g++ -Wall option includes -Wreorder. What this option does is described below. It is not obvious to me why somebody would care (especially enough to turn this on by default in -Wall). -Wreorder (C++ only) Warn when the order of member…
Peeter Joot
  • 7,848
  • 7
  • 48
  • 82
175
votes
7 answers

What does i = (i, ++i, 1) + 1; do?

After reading this answer about undefined behavior and sequence points, I wrote a small program: #include int main(void) { int i = 5; i = (i, ++i, 1) + 1; printf("%d\n", i); return 0; } The output is 2. Oh God, I didn't see the…
gsamaras
  • 71,951
  • 46
  • 188
  • 305
142
votes
4 answers

Override compile flags for single files

I would like to use a global set of flags for compiling a project, meaning that at my top-level CMakeLists.txt file I have specified: ADD_DEFINITIONS ( -Wall -Weffc++ -pedantic -std=c++0x ) However, for a specific file (let's say "foo.cpp") in a…
J.B. Brown
  • 1,753
  • 2
  • 13
  • 14
135
votes
10 answers

Custom Compiler Warnings

When using the ObsoleteAtribute in .Net it gives you compiler warnings telling you that the object/method/property is obsolete and somthing else should be used. I'm currently working on a project that requires a lot of refactoring an ex-employees…
Micah
  • 111,873
  • 86
  • 233
  • 325
128
votes
10 answers

How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?

I'd like to know what switch you pass to the gcc compiler to turn off unused variable warnings? I'm getting errors out of boost on windows and I do not want to touch the boost code: C:\boost_1_52_0/boost/system/error_code.hpp: At global…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
127
votes
3 answers

"Delegate subtraction has unpredictable result" in ReSharper/C#?

When using myDelegate -= eventHandler ReSharper (version 6) issues: Delegate subtraction has unpredictable result The rational behind this is explained by JetBrains here. The explanation makes sense and, after reading it, I'm doubting all my uses…
user166390
1
2 3
99 100