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

Username
  

Password
  





  MISRA AC SLSF:2023 AMD1 and AMD2 available
Posted by: misra-ac - 05-06-2024, 03:45 PM - Forum: MISRA AC SLSF discussions - No Replies

MISRA AC SLSF:2023 Amendment 1 and MISRA AC SLSF:2023 Amendment 2 (which contains modifications that bring the guidelines up to date for MATLAB releases R2023b and R2024a, respectively) are now available as free downloads from the "MISRA AC resources" section of this Bulletin Board.

Print this item

  MISRA AC SLSF:2023 AMD2
Posted by: misra-ac - 05-06-2024, 03:37 PM - Forum: MISRA AC resources - No Replies

This Amendment to MISRA AC SLSF:2023 contains modifications that bring the guidelines up to date for MATLAB release R2024a



Attached Files
.pdf   MISRA AC SLSF 2023 AMD2.pdf (Size: 447.66 KB / Downloads: 5)
Print this item

  Rule 0.0.1
Posted by: gdavis - 24-05-2024, 05:20 AM - Forum: 4.0 Language independent issues - Replies (1)

Hello,

I apologize for this basic question, but can somebody please walk me through the first first five lines of MISRA C++ 2023 Rule 0.0.1?

bool f0();

int32_t f1( int32_t c, int32_t &res )
{
  if ( false && f0() ) { }       // Compliant - statement is considered to be reachable
  ...

In particular, why is the empty block statement ("{ }") considered to be reachable? My thinking is:

The condition of the if statement is considered a constant expression in C++17, one that evaluates to false. Therefore, we follow the third bullet point:

  • The blocks linked by the edges from a condition of a selection-statement or an iteration-statement are all considered reachable, except when the condition is a constant expression, in which case only the blocks linked by edges selected by the condition are considered reachable.

So, this seems to me that we should consider the empty block statement to be unreachable.

Also, what is the purpose of the first two bullet points:
  • Both operands of a reachable logical AND (&&) or logical OR (||) operator are considered reachable
  • All three operands of a reachable conditional operator ( ? : ) are considered reachable

Rule 0.0.1 is concerned with statements, so I don't see how subexpressions matter unless these rules are meant to convey that an expression such as ( false && f0() ) is potentially throwing and/or not a constant expression (for the purposes of this rule).. But, I feel like I may be reading too much into this.

Thank you in advance.

Print this item

  Exemplar Suite for MISRA C++
Posted by: gdavis - 21-05-2024, 09:58 PM - Forum: General questions - Replies (1)

Hello,

Is there an Exemplar suite for MISRA C++ (either 2023 or 2008?). Looking around, I could not find one, but I wanted to check to make sure I am not missing anything.

Thank you!

Best Regards,

-Greg

Print this item

  Application of Rule 15.0.1 to Abstract Interface Classes
Posted by: nehalpatel - 14-05-2024, 06:19 PM - Forum: 4.15 Special member functions - Replies (3)

It seems rule 15.0.1 has conflicting requirements for pure virtual / abstract classes with no data members. e.g. if we create the following classes:

Code:
class CanMessage {
public:
  CanMessage();

  // Required for inheritance
  virtual ~CanMessage() = default;

  // Want to move and copy through derived classes
  CanMessage(const CanMessage&) noexcept = default;
  CanMessage(CanMessage&&) noexcept = default;
  CanMessage& operator=(const CanMessage&) & noexcept = default;
  CanMessage& operator=(CanMessage&&) & noexcept = default;

  virtual uint32_t Id() = 0;
  virtual uint8_t DataLength() = 0;
  virtual std::span<std::byte> Data() = 0;
};

class CanClassicMessage : public CanMessage {
public:
  CanClassicMessage(uint32_t id, uint8_t data_length) : CanMessage{}, id_{id} data_length_{data_length} {}
  ~CanClassicMessage() noexcept override = default;

  CanClassicMessage(const CanClassicMessage&) noexcept = default;
  CanClassicMessage(CanClassicMessage&&) noexcept = default;
  CanClassicMessage& operator=(const CanClassicMessage&) & noexcept = default;
  CanClassicMessage& operator=(CanClassicMessage&&) & noexcept = default;

  uint32_t Id() override { return id_; }
  uint8_t DataLength() override { return data_length_; }
  std::span<std::byte> Data() { return data_; }
 
private:
  uint32_t id_;
  uint8_t data_length_;
  std::array<std::byte, 8> data_;
};

class CanFDMessage : public CanMessage {
public:
  CanFDMessage(uint32_t id, uint8_t data_length) : CanMessage{}, id_{id} data_length_{data_length} {}
  ~CanFDMessage() noexcept override = default;

  CanFDMessage(const CanFDMessage&) noexcept = default;
  CanFDMessage(CanFDMessage&&) noexcept = default;
  CanFDMessage& operator=(const CanFDMessage&) & noexcept = default;
  CanFDMessage& operator=(CanFDMessage&&) & noexcept = default;

  uint32_t Id() override { return id_; }
  uint8_t DataLength() override { return data_length_; }
  std::span<std::byte> Data() { return data_; }

private:
  uint32_t id_;
  uint8_t data_length_;
  std::array<std::byte, 64> data_;
}

Per the rule, we either need 
  • a protected non-virtual destructor.
  • Unmovable class that has a public virtual destructor.

However these prevent us from being able to create a std::unique_ptr to the base class (and allow the derived classes to manage their data through their destructors), or prevents us from being able to copy or move one CanClassicMessage to another CanClassicMessage, if the base copy/move constructors are deleted.

There is an exception for Aggreagate types, but it seems there needs to be an other one for an Interface/Abstract class which holds no data.

Print this item

  A13-5-4 opposite operator clarification
Posted by: aromauld - 26-04-2024, 03:34 PM - Forum: AUTOSAR C++:2014 rules - Replies (1)

We would like to get clarification on what "opposite operators" means.

The referenced JSF guideline says (such as == and !=) which implies there are others, but there are no examples present other than "!= and ==". 

Presumably this includes relational operators, but it doesn't discuss how. This rule would seemingly imply that <= should be implemented using >=. But would this mean that it is considered non-compliant to implement it with operator >?


Code:
inline bool operator<=(const X& lhs, const X& rhs) { return !(lhs > rhs); }

Are relational operators allowed to call any other relational operators? Are there any other pairings that are considered opposites for this rule?

Print this item

  C++17 [[fallthrough]]; attribute and (Rule 6-4-3 and Rule 6-4-5)
Posted by: mshawa - 22-04-2024, 06:29 PM - Forum: 6.6 Statements (C++) - Replies (1)

Given the response from:  Rule 6-2-3 and C++17 [[fallthrough]]; attribute (misra.org.uk)
Should Rule 6-4-3(A switch statement shall be a well-formed switch statement) and Rule 6-4-5(An unconditional throw or break statement shall terminate every non-empty switch-clause) also have an exception for the [[fallthrough]]; attribute when used in an empty switch case?

Print this item

  Further guidance on MISRA-C 2012 Rule 10.6
Posted by: mshawa - 09-04-2024, 02:29 PM - Forum: 8.10 The essential type model - Replies (1)

MISRA-C 2012 D.3 states that UTLR/STLR rules are only applied to integer constant expressions for operators that explicitly specify this in D.7. D.7 further states that the essential type is the standard type unless otherwise listed and does not specify a non-standard essential type for sizeof.


Given the following example: 
Code:
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
extern uint16_t u16;
extern uint32_t u32;

extern void foo( void );
void foo( void ) {
    uint32_t case1 = (sizeof(uint32_t) + sizeof(uint32_t)) + u16; /*Case 1*/
    uint32_t case2 = u32 + u32 + u16; /*Case 2*/
    uint32_t case3 = sizeof(uint32_t) + (sizeof(uint32_t) + u16);/*Case 3*/
    uint32_t case4 = sizeof(uint32_t) + u16 + sizeof(uint32_t); /*Case 4*/
}

Which of the cases violates Rule 10.6 while providing the rationale?

Print this item

  MISRA AC SLSF:2023 AMD1
Posted by: david ward - 05-04-2024, 01:56 PM - Forum: MISRA AC resources - No Replies

This Amendment to MISRA AC SLSF:2023 contains modifications that bring the guidelines up to date for MATLAB release R2023b



Attached Files
.pdf   MISRA AC SLSF 2023 AMD1.pdf (Size: 444.31 KB / Downloads: 9)
Print this item

  Rule 6-2-3 and C++17 [[fallthrough]]; attribute
Posted by: kafka - 27-03-2024, 02:44 PM - Forum: 6.6 Statements (C++) - Replies (1)

Should the C++17 [[fallthrough]]; attribute be given an exception for MISRA C++ 2008 Rule 6-2-3 (a null statement shall appear on a line by itself)?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

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

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 623
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 554
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 425
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,031
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 597
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 717
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 433
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 532