compiler-warnings

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

依然范特西╮ 提交于 2019-11-26 20:19:54
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 to un-comment the pDC formal argument in order to compile, but I'm confused as to how/why a C++ function can compile (with no warnings) when the formal argument only has a type and not a name: void foo(int) { int x = 3; } int main() { foo(5); return 0; } Shouldn't this generate at least a warning (with -Wall or /W4)? It doesn't seem to. Am I missing

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

ⅰ亾dé卋堺 提交于 2019-11-26 19:42:15
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 pieces of code. I've seen two ways of doing that so far. The first one is to use #pragma warning( push ) and #pragma warning( pop ) : #pragma warning( push ) #pragma warning( disable: ThatWarning ) //code with ThatWarning here #pragma warning( pop ) The second is to use #pragma warning( default ) : #pragma warning( disable: ThatWarning ) //code with

Avoid warning 'Unreferenced Formal Parameter'

北城余情 提交于 2019-11-26 19:22:58
问题 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 Function(int param); }; void Child::Function(int param) { ;//Do nothing } When I compile the sub-class .cpp file, I get this error warning C4100: 'param' : unreferenced formal parameter As a practice, we used to treat warnings as errors. How to avoid the above

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

丶灬走出姿态 提交于 2019-11-26 19:14:03
问题 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 save:&error]; NSAssert1(saved, @"Dude!!1! %@!!!", error); Xcode reports that saved is an unused variable, when of course it isn't. I suspect this is because NSAssert1 is a macro. The NS_BLOCK_ASSERTIONS macro is not defined, so Objective C assertions are

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

浪子不回头ぞ 提交于 2019-11-26 18:58:03
问题 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 had no luck searching the GCC documentation. I thought I might have the var automatically used globally inside the same macro but I couldn't think of any way to do it. Does anyone know of a way to hide that warning in GCC? 回答1: Just saw this thread

Disable warnings in Xcode from frameworks

余生颓废 提交于 2019-11-26 18:52:23
问题 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 project now. Is there a way to disable warnings for those specific libraries? 回答1: If your third-party libraries are added as a separate target, you can check Inhibit all warnings for that specific target to turn all warnings off. If your library is

How to disable unused code warnings in Rust?

梦想的初衷 提交于 2019-11-26 18:39:44
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 warnings back on for anything serious, but I am just tinkering with the language and this is driving me bats. I tried adding #[allow(dead_code)] to my code, but that did not work. Arjan You can either: Add an allow attribute on a struct, module, function, etc.: #[allow(dead_code)] struct SemanticDirection; Add a crate-level allow attribute ; notice the ! : #![allow

Why does throwing 2 exceptions in a row not generate an unreachable code warning?

拜拜、爱过 提交于 2019-11-26 17:47:45
问题 Why do the following lines of code not create a compiler warning? void Main() { throw new Exception(); throw new Exception(); } As I see it, the compiler should inform you that the second throw exception cannot be reached. 回答1: It is clearly a compiler bug, and it was introduced in C# 3.0 -- right around the time that I heavily refactored the reachability checker. This is probably my bad, sorry. The bug is completely benign; basically, we just forgot a case in the warning reporter. We

g++ How to get warning on ignoring function return value

天大地大妈咪最大 提交于 2019-11-26 17:40:33
问题 lint produces some warning like: foo.c XXX Warning 534: Ignoring return value of function bar() From the lint manual 534 Ignoring return value of function 'Symbol' (compare with Location) A function that returns a value is called just for side effects as, for example, in a statement by itself or the left-hand side of a comma operator. Try: (void) function(); to call a function and ignore its return value. See also the fvr, fvo and fdr flags in §5.5 "Flag Options". I want to get this warning,

Why “not all control paths return a value” is warning and not an error?

倖福魔咒の 提交于 2019-11-26 17:23:00
问题 I was trying to answer this question. As suggested by the accepted answer, the problem with that code is that not all control paths are returning a value. I tried this code on the VC9 compiler and it gave me a warning about the same. My question is why is just a warning and not an error? Also, in case the path which doesn't return a value gets executed, what will be returned by the function (It has to return something) ? Is it just whatever is there on top of the stack or is the dreaded