compiler-warnings

Checking the gcc version in a Makefile?

被刻印的时光 ゝ 提交于 2019-11-28 06:11:39
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 recent gcc is used ? I wouldn't say its easy, but you can use the shell function of GNU make to execute a shell command like gcc --version and then use the ifeq conditional expression to check the version number and set your CFLAGS variable appropriately. Here's a quick example makefile: CC = gcc GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g') CFLAGS = -g ifeq "$(GCCVERSION)" "4.4.3"

Returning reference to a local variable

陌路散爱 提交于 2019-11-28 05:50:33
问题 Why can this code run successfully in Code::block. The IDB just reports warning: "reference to local variable ‘tmp’ returned", but ouput the result "hello world" successfully. #include <iostream> #include<string> using namespace std; const string &getString(const string &s) { string tmp = s; return tmp; } int main() { string a; cout<<getString("hello world")<<endl; return 0; } 回答1: Maybe this link will help you. 回答2: Upon leaving a function, all local variables are destroyed. By returning a

Initialise string function result?

。_饼干妹妹 提交于 2019-11-28 04:58:05
I've just been debugging a problem with a function that returns a string that has got me worried. I've always assumed that the implicit Result variable for functions that return a string would be empty at the start of the function call, but the following (simplified) code produced an unexpected result: function TMyObject.GenerateInfo: string; procedure AppendInfo(const AppendStr: string); begin if(Result > '') then Result := Result + #13; Result := Result + AppendStr; end; begin if(ACondition) then AppendInfo('Some Text'); end; Calling this function multiple times resulted in: "Some Text" the

How to ignore compiler warning when using Obsolete attribute on a class used with a Knowntype attribute

拥有回忆 提交于 2019-11-28 04:49:54
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 attribute with a type that is marked with the Obsolete attribute and is causing a compiler warning is expected. However, in our project we have warnings treated as errors so ignoring the warning isn't an option. Is there a compiler directive to suppress this warning? The following usage causes a compiler warning: ///ProductTemplateDataSet is marked with the Obsolete attribute [KnownType(typeof

Compiler warning: lambda return type cannot be deduced

为君一笑 提交于 2019-11-28 04:49:09
问题 Consider this example: #include <algorithm> #include <iostream> int main() { std::string str = "abcde4fghijk4l5mnopqrs6t8uvwxyz"; std::string str2; std::remove_copy_if(str.begin(), str.end(), std::back_inserter(str2), [](char& c) { if (std::isdigit(c)) return true; // <----- warning here else return false; } ); std::cout << str2 << '\n'; } With GCC 4.6.1, this compiles fine and prints expected output (the alphabet) but I get a warning saying "lambda return type can only be deduced when the

Avoid warning in wrapper around printf

巧了我就是萌 提交于 2019-11-28 03:53:50
问题 I have an error reporting functionality in my little C library I'm writing. I want to provide an errorf function in addition to the plain error function to allow embedding information in error messages easily. /* * Prints a formatted error message. Use it as you would use 'printf'. See the * 'sio_error' function. */ void sio_errorf(const char *format, ...) { // Print the error prefix if (g_input == STDIN) fputs("error: ", stderr); else fprintf(stderr, "%s: ", g_progname); // Pass on the

How to compile without warnings being treated as errors?

别等时光非礼了梦想. 提交于 2019-11-28 03:53:18
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 any way I can compile successfully in spite of the warnings? Sure, find where -Werror is set and remove that flag. Then warnings will be only warnings. You can make all warnings being treated as such using -Wno-error . You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't

Multiple methods named “count” found with mismatched result, parameter type or attributes

帅比萌擦擦* 提交于 2019-11-28 03:24:26
问题 Since the update to Xcode 5.1 I can't archive my project any more. Xcode always says "Multiple methods named "count" found with mismatched result, parameter type or attributes. This problem is new and simulator and running on device works fine. Here is the code: for ( int i = 0; i<[parseJSONArray count];i++){ for (int j = 0; j<[JSON[@"data"][@"menu"][i][@"item"] count];j++){ [pictureURL addObject:JSON[@"data"][@"menu"][i][@"item"][j][@"image"]]; } } Xcode shows the error at this point : [JSON

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

China☆狼群 提交于 2019-11-28 03:17:27
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 lines of code. Does Xcode have any tool to detect this? Quinn Taylor Xcode allows you to (un)check settings for specific compiler warnings that can warn you of some types of unused code. (Select the project in the source list and File > Get Info, then select the Build tab.) Here are a few (which show up for Clang and GCC 4.2 for me) which may be of

disable warning c4702 seems not work for VS 2012

寵の児 提交于 2019-11-28 02:52:54
问题 I have some code for testing that i added upfront the rest of the code, so the rest would never be reached in the test. Since i have warning level 4 set, this results in an c4702: unreachable-code warning I tried disabling like this: //do something return 0; /*-------------------------------------------------------------------------*/ #pragma warning(disable: 4702) //real code but the compiler still moans. And because i have set to treat every warning as an error, this won't compile... I am