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
126
votes
7 answers

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't like fix all the warnings. Is there a way I can…
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
122
votes
8 answers

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 have an OO way of dealing with casting. Turns out…
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
109
votes
7 answers

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 pages that are trying to use this event! What gives? Is…
jedmao
  • 10,224
  • 11
  • 59
  • 65
106
votes
6 answers

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 warnings, or vice versa? I haven't been able to find…
Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
106
votes
8 answers

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 compiler directive or way to detect those useless…
Hectoret
  • 3,553
  • 13
  • 49
  • 56
101
votes
10 answers

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. NSError *error = nil; BOOL saved = [moc…
Gregory Higley
  • 15,923
  • 9
  • 67
  • 96
94
votes
11 answers

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 FIXMEs, I'd love to have the compiler throw an…
pimlottc
  • 3,066
  • 2
  • 29
  • 24
93
votes
4 answers

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: potential divide by 0 // Code which would generate…
Jon-Eric
  • 16,977
  • 9
  • 65
  • 97
85
votes
7 answers

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 construct and have them enables in all other…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
84
votes
4 answers

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 emits a warning at compile time rather than an…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
83
votes
6 answers

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; int b; public: Test() : b(1), a(2) { …
Brendan Long
  • 53,280
  • 21
  • 146
  • 188
78
votes
4 answers

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 files. So, is there a way to completely ignore all…
bobbypage
  • 2,157
  • 2
  • 21
  • 21
75
votes
9 answers

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 way I can hide warnings for compile time asserts? I…
user34537
73
votes
4 answers

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, and it's easy to miss any real warnings in my…
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
73
votes
6 answers

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 headers. Is that intended behaviour? How do I go…
user1115652