This problem is very easy to encounter, but very hard to describe.
I use Code::Blocks 13.12, test the code snippet as follows:
auto xxx = std::string("test");
xxx.
When the trailing . is entered, there should be a context menu of auto completion popup, but it doesn't.
But if I give the right type of xxx like that:
std::string xxx = std::string("test");
xxx.
The complete menu pops up as normal. Does the completion feature not support C++11 yet? Or it just can't complete the auto type?
Go to Settings -> Compiler and find a C++ compiler with compiler flag -std=c++11, choose the flag and save.
Related
I want to define a custom set of rules to be checked at compile time. But it seems not to work.
Example:
I choose one rule directly and I'll get the expected warning.
But when I instead create a custom ruleset containing the exact same rule then I won't get the expected warning.
What could be wrong?
Edit:
void f(std::string& i) {
std::string s = i;
cout << s;
}
int main()
{
std::string s ("abc");
f(s);
}
This gives me the expected warning Warnung C26460 The reference argument 'i' for function 'f' can be marked as const (con.3). in the first case.
Even if I create a custom ruleset including all available rules, I won't get any warnings.
Here you see me selecting the custom ruleset:
Edit: The ruleset action must change one time to enable it.
When I create a new ruleset containing only the const-checks then I will get a .ruleset that does not work and look like this:
In the ruleset editor it looks like this:
When I then change its action from Warning to Error:
Then the .ruleset gets additional lines for each test case:
When I change the action back to warning it looks like this:
Now it is working as expected.
I've been able to reproduce your error with Visual Studio 2017. I don't know exactly what I changed (or if I changed anything at all), but I am able to see the code analysis warning you expect with a custom rule set.
Things I would try:
Double check the Error List window is visible and not hiding somewhere.
Open the rule set file, change the Action to Error and then back to Warning and save it. I wouldn't expect this to be the problem but it's one of the things I did and after which I started seeing the Error List window.
Seems not relevant to some questions with similar titles.
//some other code
std::string s = Lookup->getName().str();
-> break here //some other code
Note: "Lookup" is clang::DirectoryLookup http://clang.llvm.org/doxygen/classclang_1_1DirectoryLookup.html, "Lookup->getName()" is llvm::StringRef http://llvm.org/doxygen/classllvm_1_1StringRef.html.
When break at the above place, in the "Watch" pane in VS2017, the string variable "s" is initialized successfully and its value can be shown in "Watch" pane.
But when try to show(watch) the expression "Lookup->getName().str()" which is just how "s" is initialized, it says:
Lookup->getName().str() | Function llvm::StringRef::str has no address, possibly due to compiler optimizations.
the source code of StringRef::str() is:
/// str - Get the contents as an std::string.
LLVM_NODISCARD
std::string str() const {
if (!Data) return std::string();
return std::string(Data, Length);
}
And all the libraries is in debug version. Based on the above fact, there seems to be no reason for this to happen.
Such thing happens in other situations during debuging a Clang Libtooling program and it make debugging very hard.
What is the possible reason and how to solve it?
I tried #user15331850 solution and it didn't help, but setting Linker-> Debugging-> Generate Debug Info to "/DEBUG:FULL" seems giving me all variables now.
This may be due to optimization option is enabled.
You can disable the same by following these steps:
Right click on the solution
Click on the "properties"
From the left pane, click on the "Configuration Properties"
Click on "C/C++" from the sub-option
Then click on the "optimization" and select "Disabled(/Od)" from the list
That's it. Hope it works for you!!
I had this issue. I needed to change the settings for: Linker-> Debugging-> Generate Debug Info from "/DEBUG:FASTLINK" to "/DEBUG".
When using other IDEs, I usually type non-existent methods which gives an unresolved method/variable error. In the screenshot below, the method Arrangement::check for the specific arguments does not exist. I was hoping to generate this method declaration automatically now after this.
Usually other IDEs gives me an option to create methods to resolve that error (This this there in IntelliJ Idea as well as Eclipse JDT, IIRC), but in Eclipse CDT, if I type in a non-existent method it gives me an error but without any way of auto generating the missing method. Now, if I press Cmd+1 on this error, I only see two options "Rename in File" or "Rename in Workspace". You can see this in the screenshot above.
I expected to see something like "create method" or "create instance method". Is there a plugin or another way which allows me to auto generate methods like this?
I would love to have such a feature. What is possible at the moment is to implement methods out of their declaration signatures. Imagine you have the following:
class Arrangment {
public:
void check(Edge* e, Edge* f, Events& heap, CirclePairSet &cpet) const;
}
Then set the cursor on check. Press Ctrl + Shift + S to open the Source Code context menu. Select Implement method... to create a stub with the method body.
The Xcode debug area can sometimes show a summary of the most important variables inside of an object that's in the list, without the need to expand the object to see it's individual members.
Is there a way for me to teach the debugger about my own C++ objects to do the same? Let's say I have a simple class with a single member variable:
class Foo
{
int bar;
};
And the debug area should show something like the following:
aVariableOfTypeFoo = (Foo) bar=123
I know that some C++ objects are able to do this (for example std::vector shows it's size), but I wasn't able to figure out if this is somehow configurable, or if it's built-in in the debugger/Xcode itself.
I'm using Xcode 5.0.1
Thanks
You can change the summary description for a given type selecting Edit Summary Format... by right clicking on a variable of that type.
The format in your case is pretty simple and will look like this: bar = {$VAR.bar}
For more information about formats check the "Using Data Formatters" section in the Xcode User Guide (pages 42 & 43).
In C++ Builder, how can I make sure that even correctly nested code like:
void func () {
...
..
)
C++ Builder correctly nested only doing so:
void func ()
{
...
...
}
This is very stressful, because I always have to correct by hand. So how can I make which indents code as well in the first instance?
The code formatter in C++Builder 2010 should do this automatically for you. (It is invoked with CTRL-D) You’ll have to set the preferences to how you like your code to be formatted, but this is a real time saver new with this most recent release.
Select the block, then press CTRL+SHIFT+I. This is in Borland C++ 6.
I am using this free tools:
http://www.cnpack.org/index.php?lang=en
using tabs to shift marked blocks to left or right.
I don't have a copy of this to run, but the documentation mentions "Indentation, Spaces, and Line breaks" as some of the options under the formatter tab of the "Tools > Options" dialog.
What you're looking for is probably under the "Line Breaks" section.