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".
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.
I find VS19 output quite useless when working on C++ project. Consider running the example code on freshly installed VS19:
#include <iostream>
using namespace std;
class My
{
public:
void f() noexcept
{
throw exception{"A problem sir!"};
}
};
int main()
{
try
{
My m;
m.f();
}
catch (exception& ex)
{
cout << "exception caught! " << ex.what() << endl;
}
return 0;
}
What I would like to receive is: "Function throws an exception while marked as noexcept", and the cursor set on the problematic line. What I get is a new window with some general text, none of which mentions the problem, or where the problem is.
What compiler warning level have you specified? If I use the /W0 option there is no diagnostic but with any other value, /W1 through /W4, the compiler outputs the following lines:
1>filename.cpp(9,1): warning C4297: 'My::f': function assumed not to throw an exception but does
1>filename.cpp(9,1): message : __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function
Note: the diagnostic messages include the line and column numbers. If you double-click the error message it moves the cursor to the offending line.
Your verbosity parameter of MSBuild is may be too high. Go to menu: Tools -> Options. Then on the left pane select: Projects and Solutions -> Build and Run.
There you can select the appropriate verbosity of MSBuild (from Quiet to Diagnostic)
Trying to resolve your puzzle in your question:
What I get is a new window with some general text, none of which
mentions the problem, or where the problem is.
I find 90% of output useless for me.
I think what you mean is the Output window, it is always used to display output about build process.
Also, You can also program your own applications to write diagnostic messages at run time to an Output pane. To do this, use members of the Debug class or Trace class in the System.Diagnostics namespace of the .NET Framework Class Library.
For those large solution or large project, which has plenty of resource files. The build sometimes fail with unknown error. The output window is necessary for trouble-shooting.
If you think most of its info is useless,like P.PICARD suggests: Go Tools=>Projects and Solutions=>Build and Run to set its build output verbosity(!Not build log file verbosity) I suggest you change it to Minimal.
If you have a failed build and want to watch the details of the whole build process. Change it to Detailed and rebuild the project or solution.
What I would like to receive is: "Function throws an exception while
marked as noexcept", and the cursor set on the problematic line.
Have you checked the Error List window? If it disappeared,choose View > Error List, or press Ctrl++E.
Add two lines to your code sample:
int main()
{
int a = 2;
int b;
...
}
Navigate to the Error List window(I suggest you set it as Build and Intellisense):
I think it's what you want. And error list window also indicates the Variable which is not initialized or not referenced for improving your coding.
Also, you can see their line numbers. And Double-click the error message, the cursor will navigate to that line.
For C++ program, the warning level is from w0 to w4, you can set it w4 to get the high warning level.(By default it should be w3)
Right-click project=>properties=>Configuration Properties=>C/C++=>Warning Level to set it. (Have been described by Blastfurance, thanks to him!)
Change it to w0, nothing shows. Change it to w3, and it will show warnings about My::f and b but not a.(Actually I don't think you make changes to that, because w3 is by default) Change it to w4 then get the high warning level and all associated warnings display.
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.
I'm having a problem with eclipse C++. My project compiles and runs but eclipse (juno) keeps saying there are thousands of errors. For example there's a function SetRun in my code, and eclipse mentions this error: "called Invalid arguments 'Candidates are: void SetRun(?)'", whereas SetRun is of type static void SetRun (uint32_t run);
I have quite a lot of similar errors like that, where eclipse doesn't seem to understand the type of the function and puts a '?' instead.
I also have many errors like this: "symbol '*' could not be resolved."
I think this is all part of the same issue.
What can I do to make eclipse stop telling me about these errors?
I tried the proposed solution and it did not work for me. What helped was to turn off CodeAnalysis for the project. I went to Properties->C/C++ General->Code analysis. Selected Use Project Settings and turned off all errors. This is of course very annoying and unfortunate and I would be glad to know when it is properly fixed. It is a shame we can't get use of the feature any other decent IDE has.
Actually Eclipse is some kind of unstable project. Try to clean and refresh the project.
In Eclipse:
right click the project,
click properties
Expand "C/C++ general" the item in the left hand tree view by clicking the arror, (just clicking the item itself does not expand the suboptions)
From the suboptions select "Preprocessor Include Paths, Macros etc."
Click the tab "Providers" and check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".
I had a lot of these errors whicle to trying to get CODAN to run over some code which was destined for a Mac. My Mac SDK libraries were included via symlinks as in this question (but not all of them - stay tuned!) In the end, it turned out that I didn't have all the headers included. For example, I had the following function call:
IORegistryEntryGetParentEntry(service, kIOServicePlane, &parent);
Which was giving the error:
Invalid arguments 'Candidates are: ? IORegistryEntryGetParentEntry(?,?,?)'
Now, the correct signature of the function, defined in IOKit/IOKitLib.h (which I did have) is:
kern_return_t IORegistryEntryGetParentEntry(
io_registry_entry_t entry,
const io_name_t plane,
io_registry_entry_t *parent );
Now, if we take the first argument and trace the type definitions, we get:
typedef io_object_t io_registry_entry_t; (in IOKit/IOTypes.h)
typedef mach_port_t io_object_t; (in IOKit/IOTypes.h)
typedef mach_port_name_t mach_port_t; (in mach/port.h)
typedef natural_t mach_port_name_t; (in mach/port.h)
And then! I didn't have the include which defined __darwin_natural_t. This include was actually in i386, which I didn't have in my symlink directory. Adding it completed the chain:
typedef __darwin_natural_t natural_t; (in i386/vm_types.h)
typedef unsigned int __darwin_natural_t; (in i386/_types.h)
Finally, CODAN knew what type argument 1 of IORegistryEntryGetParentEntry() was supposed to be, and the error changed to:
Invalid arguments 'Candidates are: kern_return_t IORegistryEntryGetParentEntry(io_registry_entry_t ,?,io_registry_entry_t*)'
I repeated this "type-trace" for the other arguments, and found that the error disappeared (I didn't even need to rebuild the index, but YMMV). Of course, you would need to find the headers that you need and may sure they are included - the above is just an example!
I had the same problem with a few functions as well. It turned out that the argument was, after several typedefs, an __int64, which is not defined (not standard). I only had to define it in my project and this solved the problem.
Project->Properties->C/C++ General->Paths and Symbols->Symbols->C++ Source File->add
name: __int64
value: long long
(or instead of "long long" maybe you could use one of the values from this answer)
Edit:
By the way, I saw a bug report about this very issue in the Eclipse bugzilla, so maybe defining __int64 won't be necessary in the future
I can compile the solution with no errors, but when I'll try to run it, I get a crash window:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "<myformname>.resources" was corerctly embedded or linked into assembly "<myprojectname>" at compile time, or that all the satellite assemblies required are loaded and fully signed.
And after I press Break it throws me to the line:
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
If I comment this line out, everything works just fine, but my program doesn't have icon.
Anyone else had this problem? Found a solution? I couldn't find anything clear enough for me to understand, problem is really annoying me, only solution I found was to declare my form class before any other classes, but I don't even have any other classes in my solution?
I also have only one project in this solution, ms support said something about having multiple projects, which I don't have, so it was no use either.
Take a look here :
http://www.mztools.com/articles/2005/MZ2005007.aspx
The exception is thrown because your icon cannot be located. You will probably need to compiles your resources under one .dll and put this under en-US subfolder on your project output. It did the trick for me at least. There are probably other solutions to your problem too.
Do not panic like I did. The root cause of the problem is that the compiled resource file is different from the one that is asked to load at runtime. This happens because the underlying build-script cannot detect the filename or namespace changes made after the form is created.
For example, At first we started a project named x . And our $(RootNamespace) becomes x. And we created a form named y. So our XML resource file y.resx gets compiled into x.y.resource . At this point the icon change works.
Now somehow we changed the project name or the namespace to z. But our $(RootNamespace) remains the x. While at compile-time it wrongly generates old x.y.resource, but at links-time it links z.y.resource. And at this point the icon change does not work.
It can also happen if the form is under some nested namespace which is not known in the project file.
It can be fixed by changing the compilation output of the y.resx file . It can be done by right-clicking the resource and changing the Resource Logical Name to $(RootNamespace).%(Filename).resources .
I will also make sure that ProjectName,AssemblyName and RootNamespace are the same in the .vcxproj file. Somehow if the form is declared under a nested namespace like RootNamespace.gui , then the output file of the resource should be $(RootNamespace).gui.%(Filename).resources .