Questions tagged [compiler-warnings]

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

compiler-warnings
Filter by
Sorted by
Tagged with
520 votes
14 answers
262k views

How do you disable dead code warnings at the crate level in Rust?

While tinkering in Rust, I repeatedly encountered a lot of dead code warnings that made it difficult to focus. I tried using the outer attribute #[allow(dead_code)], but it only silences one warning ...
Andrew Wagner's user avatar
354 votes
21 answers
42k views

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"...
n. m. could be an AI's user avatar
325 votes
10 answers
199k views

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's user avatar
  • 54.3k
322 votes
9 answers
234k views

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 ...
Matt Joiner's user avatar
299 votes
6 answers
192k views

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 ...
android developer's user avatar
294 votes
10 answers
1.2m views

Message "warning: implicit declaration of function"

My compiler (GCC) is giving me the warning: warning: implicit declaration of function Why is it coming?
Angus's user avatar
  • 12.4k
259 votes
8 answers
107k views

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 ...
user541686's user avatar
  • 207k
223 votes
11 answers
328k views

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 ...
Atomix's user avatar
  • 13.7k
194 votes
4 answers
172k views

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 <Foundation/Foundation.h&...
monkeyboy's user avatar
  • 1,961
182 votes
6 answers
69k views

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 ...
Peeter Joot's user avatar
  • 8,028
175 votes
7 answers
18k views

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

After reading this answer about undefined behavior and sequence points, I wrote a small program: #include <stdio.h> int main(void) { int i = 5; i = (i, ++i, 1) + 1; printf("%d\n"...
gsamaras's user avatar
  • 72.7k
146 votes
4 answers
111k views

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, ...
J.B. Brown's user avatar
  • 1,793
143 votes
11 answers
59k views

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 ...
Micah's user avatar
  • 114k
133 votes
7 answers
297k views

How can I compile without warnings being treated as errors?

The problem is that the same code that compiles well on Windows, is unable to compile on Ubuntu. Every time I get this error: cc1: warnings being treated as errors Now, it's big code base and I don'...
Saurabh Verma's user avatar
131 votes
10 answers
278k views

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/...
WilliamKF's user avatar
  • 42.1k
127 votes
3 answers
34k views

"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 ...
user avatar
122 votes
8 answers
192k views

Java Class.cast() vs. cast operator

Having being taught during my C++ days about evils of the C-style cast operator I was pleased at first to find that in Java 5 java.lang.Class had acquired a cast method. I thought that finally we ...
Alexander Pogrebnyak's user avatar
112 votes
7 answers
34k views

How do I get rid of "[some event] never used" compiler warnings in Visual Studio?

For example, I get this compiler warning, The event 'Company.SomeControl.SearchClick' is never used. But I know that it's used because commenting it out throws me like 20 new warnings of XAML ...
jedmao's user avatar
  • 10.3k
107 votes
6 answers
68k views

Visual Studio warning level meanings?

On the build tab in a Web Application project I have a setting called "Warning Level". I can set a value from 0 to 4. What do these values mean? Will a value of 0 be more strict and generate more ...
Jon Tackabury's user avatar
106 votes
8 answers
48k views

How to detect unused methods and #import in Objective-C

After working a long time on an iPhone app, I realized that my code is quite dirty, containing several #import and methods that are not called or useful at all. I would like to know if there's any ...
Hectoret's user avatar
  • 3,573
102 votes
10 answers
66k views

How can I get rid of an "unused variable" warning in Xcode?

I understand exactly why unused variable warnings occur. I don't want to suppress them in general, because they are incredibly useful in most cases. However, consider the following (contrived) code. ...
Gregory Higley's user avatar
96 votes
11 answers
43k views

How to intentionally cause a custom java compiler warning message?

I'm about to commit an ugly temporary hack in order to work around a blocking issue while we wait for an external resource to be fixed. Aside from marking it with a big scary comment and a bunch of ...
pimlottc's user avatar
  • 3,086
94 votes
4 answers
58k views

Selectively disable GCC warnings for only part of a translation unit

What's the closest GCC equivalent to this MSVC preprocessor code? #pragma warning( push ) // Save the current warning state. #pragma warning( disable : 4723 ) // C4723: ...
Jon-Eric's user avatar
  • 17.1k
87 votes
4 answers
14k views

Does there exist a static_warning?

I'm aware of this question which mentions Boost's "STATIC WARNING", but I'd like to ask again, specifically, how I could implement a static_warning which operates similarly to static_assert but only ...
Kerrek SB's user avatar
  • 470k
85 votes
7 answers
72k views

Is using #pragma warning push/pop the right way to temporarily alter warning level?

Once in a while it's difficult to write C++ code that wouldn't emit warnings at all. Having warnings enabled is however a good idea. So it is often necessary to disable warnings around some specific ...
sharptooth's user avatar
  • 169k
83 votes
6 answers
38k views

Why should I initialize member variables in the order they're declared in?

I was writing some code today and got a weird compile error, which seems to be caused by initializing member variables in a different order than they were declared. Example: class Test { int a; ...
Brendan Long's user avatar
  • 53.7k
78 votes
4 answers
31k views

Ignore all warnings in a specific file using LLVM/Clang

There are some files in my iOS project that have some warnings, and I want to ignore those warnings. I don't want to disable warnings in the entire project (know how to do that), just some specific ...
bobbypage's user avatar
  • 2,157
77 votes
4 answers
53k views

What does casting to `void` really do? [duplicate]

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; ...
Ruslan's user avatar
  • 18.6k
77 votes
3 answers
37k views

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 ...
lofidevops's user avatar
  • 16.1k
76 votes
9 answers
108k views

How can I hide "defined but not used" warnings in GCC?

I have a bunch of compile time asserts, such as: CASSERT(isTrue) or CASSERT2(isTrue, prefix_) When compiling with GCC I get many warnings like 'prefix_LineNumber' defined but not used. Is there a ...
user avatar
75 votes
5 answers
32k views

Disable warnings in Xcode from frameworks

I have imported the three20 project into my project, and when I upgraded to Xcode 4.2 with iOS 5, a bunch of warnings appeared in the project. I don't care about them, but they make a lot of noise, ...
Micah Hainline's user avatar
73 votes
6 answers
21k views

What's up with the thousands of warnings in standard headers in MSVC -Wall?

Some people seem to advise you use -Wall, but when I did it on a small test project which just has a main.cpp with some includes, I get 5800 warnings most of them in standard headers or in windows ...
user avatar
70 votes
5 answers
114k views

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 { ...
Edd's user avatar
  • 8,510
69 votes
7 answers
142k views

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 <stdio.h> #include <string.h> int main() { char ...
bigl's user avatar
  • 1,073
68 votes
7 answers
51k views

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 ...
STenyaK's user avatar
  • 1,077
66 votes
8 answers
47k views

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 ...
Navaneeth K N's user avatar
64 votes
3 answers
11k views

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 ...
Svish's user avatar
  • 155k
62 votes
3 answers
50k views

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 ...
Jace Rhea's user avatar
  • 4,990
62 votes
7 answers
84k views

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-...
bdhar's user avatar
  • 22.2k
61 votes
3 answers
165k views

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. ...
F. P.'s user avatar
  • 5,048
61 votes
10 answers
60k views

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 ...
Alexandru's user avatar
  • 25.5k
61 votes
9 answers
90k views

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 ...
IttayD's user avatar
  • 28.7k
61 votes
4 answers
31k views

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,...
Andrew Coleson's user avatar
60 votes
5 answers
19k views

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(); ...
Barry's user avatar
  • 293k
59 votes
6 answers
150k views

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 ...
Mircea Ispas's user avatar
  • 20.5k
56 votes
8 answers
58k views

Checking the gcc version in a Makefile?

I would like to use some gcc warning switchs that aren't available in older gcc versions (eg. -Wtype-limits). Is there an easy way to check the gcc version and only add those extra options if a ...
Gene Vincent's user avatar
  • 5,299
56 votes
4 answers
30k views

Is it wise to ignore gcc/clang's "-Wmissing-braces" warning?

Consider the following program: #include <array> int main() { std::array<int, 1> x = { 0 }; // warning! x = { { 0 } }; // no warning return 0; } The first initialization leads to ...
Philipp Claßen's user avatar
55 votes
6 answers
26k views

Why is there a performance warning on casting pointer to bool?

This question extends Why use !! when converting int to bool?. I thought I was being cool when I did something like: bool hasParent() { return this->parentNode; } Where this->parentNode is ...
bobobobo's user avatar
  • 66.1k
54 votes
4 answers
17k views

How to eliminate warning about ambiguity?

I have this warning: Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word....
user1002358's user avatar
  • 2,922
53 votes
1 answer
44k views

How to get Intellij Idea to display compilation warnings?

I'm working with Intellij Idea 10 and Java 6 JDK Update 7. When I run Build --> Rebuild Project command, and the (javac) compilation generates warnings, Idea doesn't display what those warnings ...
Tommi's user avatar
  • 8,570

1
2 3 4 5
55