compiler-warnings

How to be warned about potential arithmetic errors due to type conversion?

*爱你&永不变心* 提交于 2019-11-27 16:32:10
问题 I am working on a calculation module using C#, and I bumped on this : double v = 4 / 100; I know this is a wrong initialization that returns v = 0.0 instead of v = 0.04 The c# rules says I must ensure at least one of the member is a double , like this : double v = (double) 4 / 100; double v = 4.0 / 100; However, I have many many initializations of that kind that involves integer variables operations, and I feel lazy to browse my code line by line to detect such mistakes. Instead, is it

Suppressing line specific XCode compiler warnings

末鹿安然 提交于 2019-11-27 16:30:42
问题 Similar to Ben Gottlieb's question, I have a handful of deprecated calls that are bugging me. Is there a way to suppress warnings by line? For instance: if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) { [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; } else { [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; //causes deprecation warning } All I care about is that

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

寵の児 提交于 2019-11-27 15:59:11
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 undefined behavior again? Failing to return a value from a function that has a non- void return type results

strange warning about ExtensionAttribute

怎甘沉沦 提交于 2019-11-27 15:33:34
问题 I'm getting a strange warning: The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll' There is no line number given, so it's hard to figure out what it's on about. The compiler error code is CS1685 回答1: Are you using someone's dll (or your own) which had implemented this attribute (with exactly the same name) itself as

error C2220: warning treated as error - no 'object' file generated

喜夏-厌秋 提交于 2019-11-27 14:24:11
问题 I have below class class Cdata12Mnt { public: char IOBname[ID1_IOB_PIOTSUP-ID1_IOB_TOP][BOADNAM_MAX + 4]; char ExIOBname[ID1_MAX_INF-ID1_EXIOB_U1TOP][BOADNAM_MAX + 4]; char cflpath[256]; char basetext[256]; UINT database[ID1_MAX_INF]; int State; public: char SelectPath[256]; public: int GetIOBName(int slt,char *Name); Cdata12Mnt(char *SelectPath); virtual ~Cdata12Mnt(); int GetValue(int id); int GetState() { return State; } }; And I have function as below Cdata12Mnt::Cdata12Mnt(char

C++ Boost: what's the cause of this warning?

限于喜欢 提交于 2019-11-27 13:25:26
I have a simple C++ with Boost like this: #include <boost/algorithm/string.hpp> int main() { std::string latlonStr = "hello,ergr()()rg(rg)"; boost::find_format_all(latlonStr,boost::token_finder(boost::is_any_of("(,)")),boost::const_formatter(" ")); This works fine; it replaces every occurrence of ( ) , with a " " However, I get this warning when compiling: I'm using MSVC 2008, Boost 1.37.0. 1>Compiling... 1>mainTest.cpp 1>c:\work\minescout-feat-000\extlib\boost\algorithm\string\detail\classification.hpp(102) : warning C4996: 'std::copy': Function call with parameters that may be unsafe - this

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

我的梦境 提交于 2019-11-27 11:45:44
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) { } }; int main() { Test test; return 0; } Then if I compile it with -Werror -Wall : $ g++ -Werror -Wall test.cpp test.cpp: In constructor ‘Test::Test()’: test.cpp:3:9: error: ‘Test::b’ will be initialized after [-Werror=reorder] test.cpp:2:9: error: ‘int Test::a’ [-Werror=reorder] test.cpp:6:5: error: when initialized here [-Werror=reorder] cc1plus: all warnings being

Using enum inside types - Compiler warning C4482 C++

可紊 提交于 2019-11-27 11:37:40
问题 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 qualified name? But IMO, that looks ugly. Any thoughts? 回答1: Yes, enums don't create a new "namespace", the values in the enum are directly available in the surrounding scope. So you get: enum sample { SAMPLE_ONE = 1, SAMPLE_TWO = 2 }; int main()

Ignore all warnings in a specific file using LLVM/Clang

我是研究僧i 提交于 2019-11-27 10:19:30
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 warnings from a specific file? I'm using LLVM 3.0 and Clang on Xcode 4.2. if you're just using clang, then you should use the pragma syntax for sources you maintain (assuming it is impossible to remove the warning by altering the program appropriately). here is the syntax: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmultichar"

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

若如初见. 提交于 2019-11-27 09:00:43
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. 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 generate the reachability information correctly; as others have noted, we correctly trim out the unreachable code