AUTOSAR A16-0-1: possible contradiction?
9 ビュー (過去 30 日間)
古いコメントを表示
Good morning to all community,
I'd like to ask your support for managing a situation that looks hard (for me) to deal with.
I'm trying to fix some violations detected by Polyspace about rule A16-0-1.
The more complex to fix are "aliases" like:
#define MAYBE_UNUSED __attribute__((unused))
This is a very-used macro and for sure I cannot replace it just with something like:
using MAYBE_UNUSED=__attribute__((unused));
Also I tried to replace it creating an equivalent symbol with CMAKE, but it does not allow me to do so.
Do you have any suggestion based on your experience?
Another "weird" point is this contradiction (in my opinion):
The rule A16-0-1 states: "The pre-processor shall only be used for unconditional and conditional file
inclusion and include guards, and using the following directives: (1) #ifndef,
#ifdef, (3) #if, (4) #if defined, (5) #elif, (6) #else, (7) #define, (8) #endif, (9)
#include."
Which implies that you cannot use preprocessor for aliases, macros &co...
The problem is that M16-0-6 explicitly talks about function-like macros.
M16-0-6 states: "In the definition of a function-like macro, each instance of a parameter shall
be enclosed in parentheses, unless it is used as the operand of # or ##."
Honestly I see a contradiction. We discussed it in our team, without getting big ideas.
What can you tell about this?
2 件のコメント
Walter Roberson
2022 年 8 月 15 日
Which implies that you cannot use preprocessor for aliases, macros &co...
I do not read it that way, as you are using #define which is one of the listed permitted preprocessor directives.
I would read it as not permitting preprocessort directives that are not in the list. For example not using #asm
採用された回答
Walter Roberson
2022 年 8 月 15 日
I looked at the Rationale in the AutoSar CPP14 Guidelines... and you are right, you can't do that.
Since C++17 you can use the attribute maybe_unused -- and you can use that with a "using" statement. https://en.cppreference.com/w/cpp/language/attributes/maybe_unused
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Bug Finder Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!