Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AUTOSAR C++14 M5-2-10 for unique_ptr in combination with ++ operator
#1
The AUTOSAR C++14 Guidelines  ("AUTOSAR Guidelines for the use of the C++14 language in critical and safety-related systems") contain the MISRA C++:2008 rule 5-2-10 as rule M5-2-2. M5-2-2 was modified to required but - AFAIK - nothing else was changed.

Quote:Rule M5-2-10 (required, implementation, automated)
The increment (++) and decrement ( ) operators shall not be mixed with other operators in an expression.

There is a similar MISRA C:2012/2023/2025 rule 
Quote:Rule 13.3 A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator

Also some examples are shared:
Code:
u8a = ++u8b + u8c--;  // Non-compliant
// The following sequence is clearer and therefore safer:
++u8b;
u8a = u8b + u8c;
u8c--;


While this makes makes sense for C and C++, there are differences between C and C. What about the following code:

Code:
#include <cstdint>
#include <memory>


struct Data {
        std::int32_t member;
};

std::int32_t main(){
        std::unique_ptr<Data> d = std::make_unique<Data>(12);
        d->member++;  // Compliant ?
}

Shall a AUTOSAR C++14/MISRA C++:2008 checker report a violation for  "d->member++" or is that OK?
Reply


Messages In This Thread
AUTOSAR C++14 M5-2-10 for unique_ptr in combination with ++ operator - by kth - 08-05-2026, 08:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)