how to get rid of "In class initializer for static data member ... is a C++0x extension" warning in Xcode 4 - c++

I can get rid of the warnings in the build log by adding -std=c++0x to "other c++ flags", but they still show up in the side pane. I'm guessing that the other flags are not being passed to clang or whatever is responsible for parsing code for the gui...
Any ideas?
Update:
The warnings have mostly disappeared, but I'm not sure why. And every time I think they're gone, I get a few again. I suspect that forcing a build of every project in the workspace has some effect, but I'm really at a loss.
In any case, modifying "other c++ flags" does seem to affect the GUI warnings, contrary to my assumption when I asked this question. But it takes time. Ahh, Xcode.

Use a pragma instead of a command line switch, as described in the answer to "Is there a way to suppress warnings in Xcode?"

Related

Project Settings Recommends Compiler Warning: "Suspicious Moves"

In an Xcode project, I'm getting a weird warning. What is it and is it a bad thing?
Here's the warning:
Project 'Little Hoot' - Enable Recommended Warning
This will enable the following recommended compiler warning:
Suspicious Moves
It is also recommending I updated another setting too.
Target 'Little Hoot' - Update C++ Standard Library
The 'libstdc++' C++ Standard Library is deprecated. This will update the setting for Target 'Little Hoot' to 'Compiler Default', which is the recommended value.
I have looked online and I'm unable to find an answer for at least the first warning.
The "Suspicious Moves" Project/Target setting seems to control the -Wmove compiler warning optionin LLVM/Clang, which is a group of 3 other warning options: -Wpessimizing-move, -Wredundant-move and -Wself-move.
Those options generate these warnings:
warning: moving a temporary object prevents copy elision
warning: moving a local object in a return statement prevents copy elision
warning: redundant move in return statement
warning: explicitly moving variable of type A to itself
(From the Clang documentation at http://clang.llvm.org/docs/DiagnosticsReference.html)
So it's probably not a big deal whether you accept the recommendation and enable the warning, or go without it. You just won't be told if you make things slower with those suspicious moves.
I also got this message from Xcode recently while setting up a new project. My steps were removing the reference from files (such as Info.plist), creating folders directly on Finder, and adding files back to Xcode. I suppose it's a security feature but if your case is like mine, it's only a warning.
Both of these warnings refer to settings in your project not reflecting the recommended defaults. They were probably both triggered after you upgraded your version of Xcode or imported an old project into a later version of Xcode.
Unless you have good reasons to do otherwise, it is best to follow the recommendation. The easiest way to do that is click in the yellow triangles that accompany the warnings and allow Xcode to make the appropriate changes to the settings.
You should turn all warnings on, with the exceptions of pedantic warnings, unused parameters, and auto-synthesised properties; these three warnings warn for tons of good code. Same for static analyser warnings.
Then you look at what warnings you get and fix them. If you haven't done this before, then I'll estimate that 20-40% of all warnings are actual bugs in your code.
You’ll be able to see warning detail in issue navigator section. You can fix it by selecting issue. This will show an alert stating necessary changes to be done in project settings.
Click on Perform Changes button. This will make necessary changes in Project settings and thereby removing this warning.

Cannot disable warnings caused by the Boost Library

I am trying to eliminate the warnings in my project so I can turn on the flag that treats warnings as errors. The project uses the boost library, specifically the Concept_check.hpp and cuthill_mckee_ordering.hpp files. The warnings 4510 and 4610 are shown in the concept_check.hpp file and I have tried to disable them using #pragma warning push and pop. The warnings are caused by the boost library trying to instantiate a class using the template found in concept_check.cpp when there is no constructor written for it.
My Question is this: Is there a more sure fire way that I can disable these warnings without modifying the boost code? I am using Visual studio 2010.
Perhaps you are looking in the wrong direction. As Alan Stokes pointed out, the warning is there for a reason. I have three hints that are perhaps not the answers you expect, but may bring an acceptable solution:
Instead of silencing the warning, just fix the error. I don't know your code, but there are other people that had a similar problem which was possible to fix by just declaring a variable.
Another question is: why do you want to turn all your warnings into errors? Is it really neccessary? I agree that normal code should always compile without warnings. But these warnings are not originating from your own code. Consider a static code-checker that warns you about issues where your compiler is blind about.
If you have to use -WX, move the offending code into a static object/library/module so you will be bothered about the warning only when you need to recompile this module. You could use specific compile options for this module, to get the warnings completely out of your way.
There is another possibility, but I'm not able to check whether it really works. According the Microsoft Documentation it is possible to set the warning level of specific warnings. (there are similar options for GCC). First, switch all warnings to error:
/WX
Then, set the warning level of the two offending warnings to zero:
/W04510 /W04610
A complete commandline would look like this:
cl source.cpp /WX /W04510 /W04610
The best solution would be to combine this with hint 3 above. This way, the specific compiler options are only used for the files that cause the warnings.
Maybe these solutions work.
You can disable specific warning from a .h file (#pragma warning( disable: ... ).

Erroneous "Unable to resolve identifier" in Netbeans

My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."
I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.
This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.
Minimal example:
#include <string>
int main() {
std::to_string(1);
}
EDIT: the same problem arises where using nullptr
EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.
I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!
This will solve the problem:
Right click on "Project".
Select "Code Assistance".
Clean C/C++ cache.
Restart IDE.
Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.
I had the same situation. This was occurred because I used .c file instead of .cpp
for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions:
change:__cplusplus=199711L
to:__cplusplus=201402L
for C++14
or to __cplusplus=201103L
for C++11
I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.
To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.

Eclipse complains method c_str could not be resolved

How can my program compile successfully but eclipse shows me "Semantic Errors" and how could I get rid of those errors?
The error messages I have are the following
Method 'c_str' could not be resolved (this happens also for compare and size on strings)
Here an example:
std::string someotherstring = "test";
std::string name = someotherstring.c_str();
The problem here is that it also creates follow up errors which seem all to be not true, my software compiles and runs as intended and even uses the "c_str()" returns to process messages. It seems only to be a display issue in Eclipse.
I have searched now for hours, tried to use a custom indexer but for some reason it won't go away. Maybe someone else has a good idea what to do here as Google spits out nothing about this specific problem. (I have even tried to use different C++11 standard flags as I thought it might had an impact)
I had the same problem. Solved by simply run a index -> rebuild. You can find that by clicking on the project main folder with the right button.
Cheers
If you're building your projects using mingw and using C++11, you can not use the default dialect option of -std=c++0x.
Click on 'GCC C++ Compiler' and in the Command: textbox, enter -std=gnu++0x after the g++

ZXing Library: Errors in iOS: private field 'cached_y_' is not used

I am currently trying to use the ZXing Library for an iOS Project. However I can't even get the sample Projects to work.
The ScanTest Project, as well as the ones that I created myself throw the following error in the BinaryBitmap.cpp file.
In file included from /Volumes/Macintosh HD/Users/Tim/Downloads/zxing-2.1/iphone/ZXingWidget/../../cpp/core/src/zxing/BinaryBitmap.cpp:20:
../../cpp/core/src/zxing/BinaryBitmap.h:33:7: error: private field 'cached_y_' is not used [-Werror,-Wunused-private-field]
int cached_y_;
^
1 error generated.
I searched on Google and Stackoverflow, but have not found a solution for the problem.
I have tried it with both the current stable release of XCode and the beta.
I don't know if anybody else has got this problem too, but any help would be greatly appreciated.
This is clang, right? You can read about the relevant compiler options here.
The error message is telling you which compiler flags are relevant.
-Wunused-private-field means you get warnings about private member fields of classes (or structs, ...) that are not used anywhere. The warning is because you probably did mean to use them. This would not normally stop the compilation, but...
-Werror turns warnings into errors. A lot of people use this option to force themselves to write very clean code. Taking this one out should be enough.