Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Code Inspection - typedef to using in VS2012
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

khb
Tomato Guru

Germany
337 Posts

Posted - May 22 2017 :  3:13:25 PM  Show Profile  Reply with Quote
I found another problem with Code Inspection in VS 2012 that is similar to the following:

    https://forums.wholetomato.com/forum/topic.asp?TOPIC_ID=12897

VS 2012 doesn't seem to support alias declarations that make use of the using keyword. This means that VA suggests me to convert:
typedef int test1;
into:
using test1 = int;
However, the latter doesn't compile for me in VS 2012. This happens for VA 2212 and 2217.

But I think you have another bug with detecting all typedef instances. For example, no conversion is suggested for the following line:
typedef map<CString, int, less<CString> > test2;
I would expect to be able to convert to line above to:
using test2 = map<CString, int, less<CString> >;
However, I wouldn't expect that suggestion in VS 2012

Kind regards,
Marcus

holedigger
Whole Tomato Software

145 Posts

Posted - May 22 2017 :  3:45:27 PM  Show Profile  Reply with Quote
Thanks, I have opened case=108382 to disable the using check in in VS2012 and earlier. In the meantime, you can disable the check in our options dialog.

For the map case, are you using namespace std? Do you get suggestions for the following:

#include <map>

typedef std::map<CString, int, std::less<CString> > test1;

using namespace std;
typedef map<CString, int, less<CString> > test2;


Whole Tomato Software
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - May 22 2017 :  5:24:54 PM  Show Profile  Reply with Quote
Yes, I'm using using namespace std. I have the following code:



However, if I copy that code to another file, then I don't see the problem. This means, I see that all the three instances of typedef are underlined in blue.

But I see this problem also in other files. For example, in the following code:



But I don't know what triggers this behavior.

Kind regards,
Marcus

Edited by - khb on May 22 2017 5:25:16 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - May 24 2017 :  09:21:23 AM  Show Profile  Reply with Quote
Have you turned Off the inspection "Typedef can be converted to 'using' declaration" in the VA Options Code Inspection settings?

If you have turned this off, can you please show the window:

VAssistX -> Code Inspection (beta) -> VA Code Inspection Results

are there any entries for "Typedef can be converted to 'using' declaration" in the window? I am wondering if the window and the underlining you are seeing in the file are properly in sync. It is possible the file underlining just needs to catch up.

zen is the art of being at one with the two'ness
Go to Top of Page

holedigger
Whole Tomato Software

145 Posts

Posted - May 24 2017 :  6:04:51 PM  Show Profile  Reply with Quote
I can't think why the map with std::less would occasionally fail other than not including the right headers, or including a header that confuses it (such as another definition of 'less'). Please let me know if you can isolate the trigger so I can repro.

Thanks.

Whole Tomato Software
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - May 26 2017 :  4:15:46 PM  Show Profile  Reply with Quote
I didn't turn off any Code Inspection option. Actually, every option is turned on for me:



Anyway, "VAssistX -> Code Inspection (beta) -> VA Code Inspection Results" shows the following for me:



In case the file underlining "just" needs to catch up: Even waiting for several minutes didn't change anything. The first two occurrences got underlined within a second.

Altogether I have five occurrences of map in my project where I pass std::less<...> as third parameter. I all cases I don't get the suggestion to convert it to using. All other occurrences of typedef in my project are underlined in blue as expected.

FWIW: If I hit Alt+G on the less, then I am taken to the file xstddef.

Kind regards,
Marcus
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - May 29 2017 :  09:10:38 AM  Show Profile  Reply with Quote
In the file where the 3rd typedef, with less, is not being underlined, is there any code above these typedefs?

Are you including any local header files? I am wondering if something further up the file is triggering this different behaviour.

To test this, can you try copying / moving these typedef lines to the very top of the file where you see this odd behaviour, and see if all 3 are underlined, or you still only get two of them flagged?

zen is the art of being at one with the two'ness
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - May 30 2017 :  4:14:18 PM  Show Profile  Reply with Quote
Above the code snippet I posted, there are only a few comments and defines. No further headers are included.

I just gave it a try and deleted all lines above #include<map>. I still see the same behavior. Even saving the file doesn't make a difference.

I still have no idea what could cause this. I always thought that I have quite an out-of-the-box MFC project...

Kind regards,
Marcus
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - May 30 2017 :  6:31:28 PM  Show Profile  Reply with Quote
If you have the time, can you please make a new default project, and copy this "problem" file into the new default project. Do you still see the problem with code inspection here?

I am wondering if instead of the file alone, somehow the project context matters. If you still see the problem, can you try deleting the code following these typedefs, and see if that has any effect? Perhaps the trigger is below the typedefs, that would explain why it is file specific.

zen is the art of being at one with the two'ness
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - May 31 2017 :  2:56:40 PM  Show Profile  Reply with Quote
I created a new project: MFC, dialog-based application, statically linked MFC library.

I copied one of the files where I see this issue over to the new project. I even erased everything before the six relevant lines. The issue still remained. However, suddenly all instances of CString got underlined by the red wiggly line. I then chose "Add Include" from the VA options, which added the line #include <afxstr.h> below the other two includes. And finally, the Code Inspection underlined all three typedef occurrences in blue as expected.

Adding the line #include <afxstr.h> to the code of my original project also fixes the issue. However, in that project no instance of CString is underlined in red. Also, the code compiles fine.

So, this leads to the following question: Why does VA require an additional include, while the compiler can live without it?

Kind regards,
Marcus
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - Jun 01 2017 :  08:34:01 AM  Show Profile  Reply with Quote
Thank you for the investigations. This is interesting, and yes, as you say, this raises some interesting questions.

Have you disabled the intellisense parser in VS2012? If the intellisense parser is active in VS2012 then VA does not underline code, since the underlining comes from the IDE. If in doubt, change the colour:

VA Options -> Underlining -> Underline unknown symbols using

to a distinct colour, so you can be sure who is underlining the code. Once we know where the underlining is coming from, we can start trying to pin this down.

My first guess is that Code Inspection is missing an include directory, so not following the #include statements quite right, but this is just a guess.

zen is the art of being at one with the two'ness
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - Jun 02 2017 :  3:43:07 PM  Show Profile  Reply with Quote
I haven't switched off IntelliSense in VS2012, but I changed the color of the VA underlining as you described to be sure. No matter which color I choose, the underlining of all CString instances stays red.

However, the code compiles just fine.

Kind regards,
Marcus
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - Jun 03 2017 :  08:14:41 AM  Show Profile  Reply with Quote
I have seen this sort of problem before. There is the intellisense parser in the IDE, and the compiler, but they work differently. Not always, but you can certainly end up with code that does compile, but that the intellisense parser either cannot understand, or thinks is wrong. When you throw in VA's parser, which also works slightly differently, you get some "fun" results.

If you want, you can try the setting:

IDE tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Disable Database = True

or:

IDE tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Disable Squiggles = True

As for VA, do you have a test file, or test solution, that shows the problem with the typedef not being picked up by Code Inspection that I can test here, to see if I can get the same behaviour?

If so, and you are able to share this, please submit the files via the form:

http://www.wholetomato.com/support/contact.asp

including this thread ID or URL in the description, so we can match it up.

zen is the art of being at one with the two'ness
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - Jun 06 2017 :  1:09:29 PM  Show Profile  Reply with Quote
A long time ago, I decided to stick to the default IntelliSense. At that time it gave me more consistent results. Maybe at some point of time I should give VA's parser another try, but currently I'm too busy.

I sent you a test project via the contact page. When I open it, I see the following:



Kind regards,
Marcus

Edited by - khb on Jun 06 2017 1:11:54 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
16086 Posts

Posted - Jun 06 2017 :  4:15:14 PM  Show Profile  Reply with Quote
I have the test project, many thanks for this.

I have now worked out why CString is being underlined yet the solution compiles. The header file where the underlining is happening is never included. So the underlining is correct, in that the header file is invalid if included on its own in a new cpp file. Making a matching cpp file, and starting that cpp file with:

#include "stdafx.h"
#include "CmdLine.h"

removes the underlining for me.

I am also seeing the VA problem where Code Inspection is only suggesting some of the typedef's can be replaced with using, so many thanks for the test project. I have put in a bug report for this:

case=108743

zen is the art of being at one with the two'ness
Go to Top of Page

khb
Tomato Guru

Germany
337 Posts

Posted - Jun 10 2017 :  04:29:07 AM  Show Profile  Reply with Quote
Thank you for explaining the issue with the underlined CString instances. This also explains, why I don't see this issue in my real project. And, of course, thank you very much for your effort in reproducing the problem.
Go to Top of Page

sean
Whole Tomato Software

USA
2698 Posts

Posted - Jun 16 2017 :  8:47:41 PM  Show Profile  Reply with Quote
case=108382 is implemented in build 2219
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2019 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000