Visual Studio 2017: Ruleset won't execute - visual-studio-2017

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.

Related

Using map function to map to user options to specific function

I am new to C++ and need some help with the following:
If i have no namespace this works fine as soon as i have this i get a error :
(active) E0109 expression preceding parentheses of apparent call must have (pointer-to-)
I am attaching a solution where i have implemented this code to show the error.
What i am tryng to achive is to use this map to call my menu options a user can select, it has a header file as well as the cpp implemtation file in it.
I have attached the source code with the error showing when trying to compile this.
I would greatly appreciate some help - sample attached done in visual studio Sample Code
https://www.dropbox.com/s/j5nkxabjah313wz/SampleMenu.zip?dl=0

Is there any way to make Visual Studio C++ error output useful?

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.

Eclipse CDT method auto generation support

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.

How can I access the root namespace by name - instead of simply `::`?

I am working on a c++ project (and I'm a complete c++ n00b) that uses the root namespace to access the ::tolower method in the following lines of code, but I have changed some build settings and am getting an error.
CCString * CCBReader::toLowerCase(CCString * pString) {
std::string copy(pString->getCString());
std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower);
return CCString::create(copy.c_str());
}
The build changes are essential for most of the project, and changing these is not an option. So as a workaround, I would like to try prefixing this with the root namespace. For example:
std::transform(copy.begin(), copy.end(), copy.begin(), rootns::tolower);
Is this possible? If so, how?
Since many of you have already disregarded my ideal solution as impossible, and have asked what the error is to see if you can solve it your own way, here is the relevant portion of the error:
error: '::tolower' has not been declared
The root namespace does not have a name, so there is no other way to address it.
Instead, you're going to have to re-examine your build changes, and maybe consider what exactly the error you get says. The error might not really be about namespaces. It could have been triggered by some other problem earlier in your code.

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}