compiler-warnings

Understanding -Weffc++

强颜欢笑 提交于 2019-11-27 20:13:51
Consider the following program: #include <string> struct S { S (){} private: void *ptr = nullptr; std::string str = ""; }; int main(){} This, when compiled with -Weffc++ on GCC 4.7.1, will spit out: warning: 'struct S' has pointer data members [-Weffc++] warning: but does not override 'S(const S&)' [-Weffc++] warning: or 'operator=(const S&)' [-Weffc++] That's no problem normally, except for a couple things with this example: If I comment out any of the constructor, the pointer declaration, or the string declaration, the warning disappears. This is odd because you'd think the pointer alone

How to get rid of the warning “file was built for unsupported file format” when linking with a static library?

ⅰ亾dé卋堺 提交于 2019-11-27 20:05:48
问题 I've an application which includes an external library I developed, and I'm getting the following warning message every time I compile using the device as target: mylib-release-iphonesimulator.a, file was built for unsupported file format which is not the architecture being linked (armv7). I've 2 versions of the library, both added into the project. One built for the iphonesimulator and the other for iphoneos. Even though it works well on any target (seems the compiler takes the correct

'__strong' only applies to objective-c object or block pointer types; type here is XXX" warning

大憨熊 提交于 2019-11-27 19:29:56
问题 i get many warnings of type: '__strong' only applies to objective-c object or block pointer types; type here is... the warnings are pointing to framework headers. e.g NSNotification, NSURL, NSIndexset etc.. what are they and how can i repair it? note 1: i use ARC note 2: the app seems to work edit 1: the warnings seems to originate from my pch file. which is: // // Prefix header for all source files of the 'myapp' target in the 'myapp' project // #import <Availability.h> #ifndef __IPHONE_5_0

Avoid warning 'Unreferenced Formal Parameter'

人走茶凉 提交于 2019-11-27 18:18:57
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 warning? Thanks. In C++ you don't have to give a parameter that you aren't using a name so you can just

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

半世苍凉 提交于 2019-11-27 17:55:31
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 definitely enabled. While it doesn't hurt anything, I find it untidy and annoying, and I want to suppress

Can GCC not complain about undefined references?

人盡茶涼 提交于 2019-11-27 17:30:21
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 and linked by GCC: void function() { made_up_function_name(); return; } ...even though made_up_function_name is not present anywhere in the code (not headers, source files, declarations, nor any third party library). Can that kind of code be accepted and compiled by GCC under certain conditions, without touching the actual code? If so, which? Thanks. EDIT: no previous declarations or mentions to

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

ⅰ亾dé卋堺 提交于 2019-11-27 17:17:02
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? Just saw this thread while searching for solutions to this problem. I post here for completeness the solution I found... The GCC

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

放肆的年华 提交于 2019-11-27 17:16:01
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 initializers given in the code does not match the order in which they must be executed. For instance: struct A { int i; int j; A(): j (0), i (1) { } }; The compiler will rearrange the member initializers for i and j to match the declaration order of the members, emit-ting a warning to that effect. This warning is enabled by -Wall. Consider: struct A { int i;

Disable warnings in Xcode from frameworks

两盒软妹~` 提交于 2019-11-27 17:06: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? 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 added as plain source files to your current target, you can set -w compiler flag for individual sources to mute

Which compilation flags should I use to avoid run time errors

和自甴很熟 提交于 2019-11-27 16:33:03
问题 Just learned here that -Wsequence-point comiplation flag will pop a warning when the code can invoke UB. I tried it on a statement like int x = 1; int y = x+ ++x; and it worked very nicely. Until now I have compiled with gcc or g++ only using -ansi -pedantic -Wall . Do you have any other helpful flags to make the code more safe and robust? 回答1: As alk summed up, use these flags: -pedantic -Wall -Wextra -Wconversion First, I think you don't want to use the -ansi flag, as suggested in Should I