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

Username
  

Password
  





  About MISRA-C 2023 Permit
Posted by: nghia do - 18-09-2024, 11:53 AM - Forum: General Questions - No Replies

Hi,

I would like to know when MISRA C:2023 permit is published. If no, could I understand there is no new deviation rule between MISRA-C 2012 and MISRA-C 2023

Print this item

  Rule 7.0.4 - example not compliant with 7.0.5?
Posted by: cgpzs - 12-09-2024, 12:56 PM - Forum: 4.7 Standard conversions - Replies (2)

Hi,

Rule 7.0.4 provides this example as compliant, and does not violate other rules  (like other examples)

Code:
static_cast< uint16_t >( u8 + u16 ) << 2;  // Compliant

Why doesn't this example violate 7.0.5? Bit shift applied on uint16_t will cause integral promotion from uint16_t to int, thus violating 7.0.5, or?

Thanks!

Print this item

  Rule 6.7.1 and thread storage duration
Posted by: rg99 - 10-09-2024, 06:40 PM - Forum: 4.6 Basic concepts - Replies (1)

Is Rule 6.7.1 intended to apply to local variables with thread storage duration?  For example:

Code:
typedef int int32_t;

void foo() {
    static int32_t var1{0};        // Non-compliant
    thread_local int32_t var2{0};  // Compliant ???
    /* ... */
}


While the rule specifically references "static storage duration" it is not clear what the intended impact of this rule is with respect to "thread storage duration" variables.  While local variables with thread storage duration do not suffer the same intrinsically thread-unsafe characteristics as those with static storage duration, the provided Rationale still applies.  In particular, they decrease comprehensibility, introduce temporal coupling, and can result in (reentrant) data races.

Print this item

  Rule 6.9.2: Unclear interpretation about "char"
Posted by: cgpzs - 03-09-2024, 07:52 AM - Forum: 4.6 Basic concepts - Replies (1)

Hi,

Rule 6.9.2 says it applies to "integral types constructed using the keywords char, ...". 
But it also says "it does not apply to the use of plain char".

This is confusing - is "char" allowed or not? Can you provide an example that shows where "char" is allowed and where it's not? I cannot find any in the rule explanation.

Thanks!

Print this item

  Rule R7.0.1 converting constructor question
Posted by: gdavis - 22-08-2024, 07:58 PM - Forum: 4.7 Standard conversions - Replies (1)

Hello,

Rule 7.0.1 allows for an explicit cast from bool to T when T has a converting constructor with a parameter of type bool. The example for the rule shows:

struct A
{
  explicit A ( bool );
};

A anA { true };       // Compliant - constructor

Yet, C++ requires a converting constructor to be non-explicit.

I'm not sure what the intent is, but perhaps the rule should allow for an explicit cast from B to T when T has an explicit constructor that takes a single parameter, a parameter of (possibly const-qualified) type bool.

Please advise. Thank you.

Print this item

  9.4.2 - Why C-style enums are exempted from requiring a default clause?
Posted by: cgpzs - 22-08-2024, 06:03 PM - Forum: 4.9 Statements - Replies (3)

Rule 9.4.2 requires that all switch blocks have a "default" case, for defensive programming.

This is however not required when using C-style enums, i.e. unscoped and without underlying type. Presumably because it's Undefined Behavior to cast an int out-of-range to a C-style enum, whereas it's well-defined behavior for "C++ enums". Since UB is assumed to not happen, one can assume that a C-style enum has a valid value.

However, there's a subtlety. The "range" of a C-style enum is not just the list of valid enumerators, but the smallest bitset that contains all enumerators.

So for example:

Code:
enum Foo
{
   a = 0,
   b = 1,
   c = 2,
   d = 3
};

The following code is **not** Undefined Behavior, because the valid range of this enum is 0-7 (2^3 - 1).

Code:
enum Foo x = static_cast<Foo>(7);

So I'd argue that defensive programming still applies here and a "default" case would still be needed.

What do you think?

Print this item

  A27-0-1 Unclear scope of the rule
Posted by: cgpzs - 20-08-2024, 10:36 AM - Forum: AUTOSAR C++:2014 rules - Replies (1)

Hi,

Rule A27-0-1 says:

Rule A27-0-1 (required, implementation, non-automated)
Inputs from independent components shall be validated.

This is very abstract and vague:

* What is the definition of "independent components"?
* Validated, in what context? When doing what?

The rule is in the section "Input/output library", and the code examples of this rule only talk about string manipulation/formatting functions. Can we therefore assume that this rule is only concerned with validating input passed to string manipulation/formatting functions?

Thanks!

Print this item

  Rule 10.1.2: Justification for considering volatile member functions as inappropriate
Posted by: Nicolas Huch - 14-08-2024, 03:34 PM - Forum: 4.10 Declarations - Replies (1)

I seek justification for why declaring a member function as volatile is considered an inappropriate use of the volatile qualifier.

The other inappropriate use cases (local variables, function parameters, function return types, and structured bindings) are justifiable to me since they are not bound to specific memory addresses, which may be out of scope for the C++ virtual machine to reason about. Instead, they are typically automatic variables located on the stack or only exist in registers, which conflicts with the concept of volatile.

However, a class object might be located at a specific memory address where it could abstract a memory-mapped register. Such an object must be declared as volatile. To call non-static member functions on such an object, those functions must also be declared as volatile.

The justification for all of the inappropriate use cases mentions that the behavior is not well-defined or well-understood, but the standard clearly states the behavior in the case of non-static member functions:

Declaring a non-static member function as volatile will influence the type of the this pointer as well as the member function type (12.2.2 [4]). Section 12.2.2.1 [1] further clarifies that the type of the object referred to by the this pointer is qualified with the same cv-qualifiers as those used for the non-static member function.

Additionally, MISRA Rule 10.1.2 explicitly states in a note that "a pointer or reference to a volatile entity is permitted", which contradicts the notion that declaring a volatile member function is an inappropriate use of the volatile qualifier.

Are there further aspects I am missing or wrong assumptions in my reasoning?

Kind regards
Nicolas

Print this item

  MISRA C++ 9.6.2
Posted by: gdavis - 06-07-2024, 02:20 AM - Forum: 4.9 Statements - Replies (1)

Hello,
My question is about the third example for MISRA C++ 2023 Rule 9.6.2: "A goto statement shall reference a label in a surrounding block".

void f3(int32_t i, int32_t x, int32_t y)
{
  switch( i )
  {                                   // statement A
    case 0:
      if ( x < y )
        goto L3;                      // Non-compliant
      break;
    case 1:
    L3:
      break;
  }
}

I am not sure why this is non-compliant. In terms of the amplification of the rule, "A goto statement shall be enclosed in a statement that directly encloses its reference label", statement A is the compound statement as shown above. I believe the goto statement is enclosed within statement A, and statement A directly-encloses the reference label (L3).

The MISRA C 2012 and MISRA C 2023 versions of the equivalent rule 15.3 provide a different amplification that directly addresses this: "A switch-clause that does not consist of a compound statement is treated as if it were a block"

Please let me know what you think. Thank you.

Print this item

  Explain deviation requirement
Posted by: Gabriel - 18-06-2024, 11:26 AM - Forum: 8.10 The essential type model - Replies (1)

Hello, could someone explain the following deviation requirement: 

"This deviation permit shall only be applied if the compiler's implementation has been verified to be consistent with the code generator's configuration (implicit or explicit)."

It is mentiond in rule 10.3, 10.4 and 10.8.
How to prove that this can be fullfilled? Could you refer to autocode?

Thanks!

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,170
» Latest member: Huuu
» Forum threads: 996
» Forum posts: 2,750

Full Statistics

Online Users
There are currently 251 online users.
» 0 Member(s) | 249 Guest(s)
Bing, Google

Latest Threads
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 340
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 302
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,427
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,837
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,453
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,665
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,221
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 399
MISRA 2023 Test Suite
Forum: General Questions
Last Post: grigdon
14-10-2024, 01:27 PM
» Replies: 0
» Views: 180
MISRA C:2023 ADD4
Forum: MISRA resources
Last Post: david ward
11-10-2024, 07:41 PM
» Replies: 0
» Views: 229