Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





  A7-1-1 and function parameters
Posted by: mstaron - 31-08-2022, 01:03 PM - Forum: AUTOSAR C++:2014 rules - Replies (2)

The 'A7-1-1' uses the term: 'immutable data declaration'. This is not defined in the C ++ standard, so it is unclear if this rule applies to function parameters.

Code:
int f(int x)  // Is it Non-compliant?
{
  return x;
}

Print this item

  A5-2-6 about operands consisting of a sequence of only `&&` or `||`
Posted by: zhaohui - 19-08-2022, 06:21 AM - Forum: AUTOSAR C++:2014 rules - Replies (2)

Quote:A5-2-6 (Required) : The operands of a logical && or \\ shall be parenthesized if the operands contain binary operators.

What about those cases whose oeprands consists of either a sequence of only logical && or ||?
Code:
void f()
{
    int a, b, c, d;
    if ((a < b) || (b < c) || (c < d)) // compliant or noncompliant
    {
    }
}
This should be a exceptional case for MISRA C++-2008 Rule 5-2-1 ( Each operand of a logical && or || shall be a postfix-expression ), does this exception apply for A5-2-6 either?

Print this item

  Why example in Rule A5-0-2 is non-complient
Posted by: kafka - 27-07-2022, 07:13 PM - Forum: AUTOSAR C++:2014 rules - Replies (1)

Could someone please explain why the "if (u && (boolean1 <= boolean2));" in Rule A5-0-2 is non-compliant.

Print this item

  Why example in Rule 5-0-13 is non-compliant
Posted by: kafka - 27-07-2022, 07:13 PM - Forum: 6.5 Expressions (C++) - Replies (1)

Could someone please explain why the "if ( u8 && (bool_1 <= bool_2 ) )" in Rule 5-0-13 is non-compliant.

Print this item

  Strict aliasing rule
Posted by: suruena - 25-07-2022, 10:17 AM - Forum: 8.11 Pointer type conversions - No Replies

The Rule 11.3 (category Required) disallows the conversion between two pointers to different object types, indicating in the first paragraph the possible problems due to different alignment, and in the second paragraph that even if same alignment it is undefined behavior anyway (citing C99 section 6.5p7), except if conversion to pointer to a char type.

Even if the rule is technically correct, in my opinion readers will normally focus on the first paragraph, just analysing the alignment restrictions (and endianness) of the specific platform for justifying specific deviations (like using type punning through pointer conversion for needed format conversions). For example, justifying the conversion of a uint32_t into an array of two uint16_t, or a 32-bit float into a uint32_t. However, the part about undefined behavior is probably not highlighted enough, specially now that current compilers will take advantage of this undefined behavior to generate broken code due to the type aliasing analysis (reordering assignments or even removing code as the compiler is not required to consider the dependencies between those objects due to the undefined behavior, unless aliasing through a char pointer type or due to a few other exceptions).

I think it would be much more useful for the reader to mention the "strict aliasing rule" (as this is the term normally used to warn about these problems in technical forums) and the possibility to get "miscompiled" code at high optimization levels. Also, I think it would be very appreciated to give some guidance of possible standard-compliant solutions like using memcpy instead (moreover as the compiler will probably remove the call overhead if optimizations enabled), copying into an union (which may also be optimized by the compiler, not really generating any data copy) if the compiler is compliant with C99 T3, or even disabling the strict aliasing when compiling (like using -fno-strict-aliasing in GCC), in addition to the already mentioned access through a pointer to a char type.  Even if it cannot be ensured the universal adequacy of these solutions, the readers will be warned about sophisticated compilers and the strict aliasing rule, and will be aware about possible solutions available to be considered in their specific platform. Thank you very much.

Best regards,
Santiago

Print this item

  Unions and BitFields
Posted by: [email protected] - 05-07-2022, 03:26 PM - Forum: 6.9 Classes (C++) - Replies (2)

Regarding usage of bitfields and enum, it is mention thta in certain cases it can be acceptable.

Rule 9-5-1 :  Could you please explain what it means by "all relevant implementation-defined behavious is documented"
Rule 9-6-1 :   Could you please see if the following code example would be compliant.


For exemple would the following code be acceptable with a deviation justification:

   typedef unsigned int  ubitfield_t;

    union EventSource
      {
        EventSource() { Reset(); }
        void    Reset() { all[0] = 0; }

        uint32_t all[1];
        struct EventSourceBits
        {
            ubitfield_t unused                            : 28;

            ubitfield_t unknownId            : 1;
            ubitfield_t InvalidHeader         : 1;
            ubitfield_t wrongCRC              : 1;
            ubitfield_t incompatible          : 1;

        } bits;
      };



Regards,
Charles

Print this item

  Enabling engagement from open source communities
Posted by: Kim Viggedal - 04-07-2022, 09:51 AM - Forum: C++ General - No Replies

In the interest of promoting best practices in developing safety- and security-related electronic systems and other software-intensive applications it would arguably be important to make coding guidelines, such as the coming version of MISRA C++ guidelines, highly available for anyone to use.

The open source community has been reluctant to try to implement support for checking compliance with previous MISRA C++ Guidelines in static analysis tools because they are not openly published. I'm proposing that it would be of great value to the automotive industry as a whole if MISRA C++ Guidelines were published under a copyright license which explicitly allows free use of the guidelines e.g. for use as a specification for implementing support for the Guidelines in opens source static analysis tools.

Is there anything currently preventing MISRA from taking such an approach to publishing of guidelines?

Print this item

  MISRA Unspecified Behavior - AMD 2 - Corrections
Posted by: maff_707 - 27-06-2022, 10:56 AM - Forum: General Questions - Replies (2)

Hi,

I sent you a question before for TC3 issue - indeed I noticed that the C standard has  TC3 where there are some added things, this is resolved now, but I have one more issue I didn't find an fix for:

Mainly, in the appendix H.2. Critical Unspecified behavior, there seems to be a mistake in rules mentioned for the unspecified behaviors.
Mainly for C99, unspecified behaviors with ID 41 and 42, have Rule 21.9 - but they obviously refer to dynamic allocation, which should be Rule 22.1.

Further more, IDs 43 and 44, which should refer to quick sort and binary search, have Rule 21.10 (for time and date functions) but it should be Rule 21.9.

Finally, IDs 45 and 56, which should be covered by rule 21.10 (no time and date), do not have any reference to rules which avoids the unspecified behavior.

Please see attachment image for more details.



Attached Files Thumbnail(s)
   
Print this item

  What is the intention of A15-4-4
Posted by: kth - 23-06-2022, 02:22 PM - Forum: AUTOSAR C++:2014 rules - Replies (1)

Hi experts,

A15-4-4 

Quote:Rule A15-4-4 (required, implementation, automated)

A declaration of non-throwing function shall contain noexcept specification.


provides this example (17-10):
Code:
// ...
Code:
void F1(); // Compliant - f1, without noexcept specification, declares to throw
// exceptions implicitly

// ...


The implementation of F1 is not provided.

I would assume that a matching implementation of  F1() would be, e.g. 
Code:
void F1() {
  // something ...
  throw std::runtime_error{"problem"};
}

My questions:
1. Is my implementation of F1 above correct?
2. What should a compliant static analysis tool report, when F1 does not throw?
3. Shall a compliant AUTOSAR C++ checker tool here report a violation (error/warning/...) or is this kind of a hint or note? 
4. What shall be reported for the operator()() of a lambda that does not throw and does not explicitly add noexcept (example: auto l = []() { return 42; })?
5. (Bonus question) will a similar check be added to the next version of MISRA C++?

Print this item

  Naming Conventions in MISRA C 2012
Posted by: gpotts63 - 21-06-2022, 12:21 PM - Forum: General Questions - Replies (1)

What is the meaning of different naming conventions with rules?
For example, “Rule 2.1: A project shall not contains unreachable code” versus “Rule 5-0-7: There shall be no explicit floating-integral conversions of a cvalue expression”.
It seems some companies that use MISRA support only the decimal point rules, while others support the dashed rules.
What is the difference, and/or why is there a split?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,119
» Latest member: aromauld
» Forum threads: 968
» Forum posts: 2,657

Full Statistics

Online Users
There are currently 145 online users.
» 0 Member(s) | 142 Guest(s)
Bing, Facebook, Google

Latest Threads
A13-5-4 opposite operator...
Forum: AUTOSAR C++:2014 rules
Last Post: aromauld
4 hours ago
» Replies: 0
» Views: 7
C++17 [[fallthrough]]; at...
Forum: 6.6 Statements (C++)
Last Post: mshawa
22-04-2024, 06:29 PM
» Replies: 0
» Views: 34
cvalue and constant integ...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
19-04-2024, 04:53 PM
» Replies: 1
» Views: 193
Rule 6-2-3 and C++17 [[fa...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
19-04-2024, 04:48 PM
» Replies: 1
» Views: 161
10.2.3 Amplification
Forum: 4.10 Declarations
Last Post: misra cpp
12-04-2024, 02:20 PM
» Replies: 1
» Views: 179
Rule 7.0.5 Example potent...
Forum: 4.7 Standard conversions
Last Post: misra cpp
12-04-2024, 01:54 PM
» Replies: 1
» Views: 156
Rule 0.2.4 non-compliant ...
Forum: 4.0 Language independent issues
Last Post: misra cpp
12-04-2024, 01:51 PM
» Replies: 1
» Views: 171
Further guidance on MISRA...
Forum: 8.10 The essential type model
Last Post: mshawa
09-04-2024, 02:29 PM
» Replies: 0
» Views: 90
MISRA AC SLSF:2023 AMD1
Forum: MISRA AC resources
Last Post: david ward
05-04-2024, 01:56 PM
» Replies: 0
» Views: 108
MISRA AC GMG:2023 release...
Forum: MISRA AC GMG discussions
Last Post: misra-ac
25-03-2024, 06:01 PM
» Replies: 2
» Views: 456