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
 Feature Requests
 Code Inspection - Disable in Macro
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 27 2018 :  04:41:55 AM  Show Profile  Reply with Quote
I just started using VA and noticed that code inspection flags issues that are hidden in macros. For example, a macro that contains
do{ ... } while(0)
will be flagged because the integer literal can be replaced by false.
It would be great if we could disable inspections inside macros.

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 27 2018 :  06:52:55 AM  Show Profile  Reply with Quote
Can you post an example of the macros that are hiding this code? Are the macros ALWAYS hiding the code, e.g. #if 0 #endif, or are the macros only hiding the code for some compiler settings?

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

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 27 2018 :  06:56:02 AM  Show Profile  Reply with Quote
Unfortunate choice of words, by hidden in macros I didn't mean the code gets #ifdef'd out, just that there's code that is expanded from a macro.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 27 2018 :  07:18:15 AM  Show Profile  Reply with Quote
Can you post a code example to explain what is going on here? I am not following.

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

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 27 2018 :  10:12:18 AM  Show Profile  Reply with Quote
In this code:
#include <iostream>

#define PRINT(x) do { std::cout << (x); } while(0)

int main()
{
    PRINT("Hello World!\n");
}

There's a diagnostic at the usage of PRINT that says Integer literal can be replaced with 'false'.

Edited by - Pezo on Aug 27 2018 10:12:41 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 27 2018 :  2:00:24 PM  Show Profile  Reply with Quote
Now I understand what you mean by hidden in macros. Why disable this though? The macros are still part of your code, and if you want to leave this particular code inspection check turned on, then it makes sense that it also checks the code inside the macro body.

Are you aware that you can turn off this code inspection by turning off "Integer literal can be replaced with 'true' or 'false'" setting in the settings page:

VA Options -> Code Inspection (beta)

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

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 28 2018 :  03:03:50 AM  Show Profile  Reply with Quote
You're right it's part of my code, but the macro comes (as do many macros in many code bases I suspect) from a library that I don't control, so I get a warning on every single log statement in my part of the code.
I'm aware that I can turn it off, but I'd prefer not to because it's still useful.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 28 2018 :  08:26:38 AM  Show Profile  Reply with Quote
Is the header file where the macro is defined part of your stable include directories? Or is it part of your solution?

I see the problem now, but my concern is that the macro its self is not being flagged by Code Inspection, only the calls to the macro. This makes sense, but we probably don't want to automatically stop Code Inspection from checking all macros. So I am looking for a "rule" to define macros we might want to check vs ones we don't want to check. I am not sure this will actually help, but it would be a good start point.

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

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 28 2018 :  08:30:32 AM  Show Profile  Reply with Quote
I don't know what you mean by stable include directories. The header file is in another project of the same solution, it's part of my project's AdditionalIncludes I think.

A generic rule is probably not possible, but it's common for such checks to be ignored in macros (as an option at least). A lot of clang-tidy checks do this, for example.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 28 2018 :  10:12:45 AM  Show Profile  Reply with Quote
Do you have a link for clang-tidy ignoring macros? I am still learning about clang-tidy myself, and since Clang is what we are using to power Code Inspection, this suggests that what you are looking for is already built in. I am not seeing any obvious mention of this with a quick web search myself, so perhaps using the wrong search terms.

I was asking about stable include directories since I assumed (always dangerous ) that if the macro was defined inside your solution you would be able to edit the macro definition to fix the warning at the macro level. So it made sense that the macro was being found in a 3rd party library you were using, that you were not in a good position to update.

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

Pezo
Junior Member

Austria
10 Posts

Posted - Aug 28 2018 :  10:57:01 AM  Show Profile  Reply with Quote
This would be the corresponding clang-tidy check: http://releases.llvm.org/6.0.1/tools/clang/tools/extra/docs/clang-tidy/checks/modernize-use-bool-literals.html
It has an option IgnoreMacros that is enabled by default.

Edited by - Pezo on Aug 28 2018 10:57:25 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 28 2018 :  1:06:12 PM  Show Profile  Reply with Quote
That's very straight forward when you know where to look, thank you for the link

I have put in a feature request to allow this setting to be set for this code inspection:

case=118756

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000