T O P I C R E V I E W |
Pezo |
Posted - Aug 27 2018 : 04:41:55 AM 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. |
11 L A T E S T R E P L I E S (Newest First) |
feline |
Posted - Aug 28 2018 : 1:06:12 PM 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 |
Pezo |
Posted - Aug 28 2018 : 10:57:01 AM 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.
|
feline |
Posted - Aug 28 2018 : 10:12:45 AM 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. |
Pezo |
Posted - Aug 28 2018 : 08:30:32 AM 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. |
feline |
Posted - Aug 28 2018 : 08:26:38 AM 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. |
Pezo |
Posted - Aug 28 2018 : 03:03:50 AM 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. |
feline |
Posted - Aug 27 2018 : 2:00:24 PM 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) |
Pezo |
Posted - Aug 27 2018 : 10:12:18 AM 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'. |
feline |
Posted - Aug 27 2018 : 07:18:15 AM Can you post a code example to explain what is going on here? I am not following. |
Pezo |
Posted - Aug 27 2018 : 06:56:02 AM 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. |
feline |
Posted - Aug 27 2018 : 06:52:55 AM 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? |