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

Username
  

Password
  





  Rule 8.2.8 - why aren't aliases allowed?
Posted by: cgpzs - 18-03-2025, 01:19 PM - Forum: 4.8 Expressions - Replies (1)

The rule provides this example as Non-Compliant:

Code:
    using hashPtr_t = std::uintptr_t;
    auto p2 = reinterpret_cast< hashPtr_t >( s );  // Non-compliant

However, there's nowhere in the Rule Text, Rationale or Amplification that explains why aliases are not allowed. Can you clarify?

Aliases are good for removing code duplication and ensuring the correct type is used in all contexts where it's needed; having to remove the alias and spell std::uintptr_t everywhere hurts code readability and maintainability, without any clear benefit.

Static analyzers can easily detect the usage of std::uintptr_t even if it's behind an alias.

Print this item

  Typo in Appendix C of MISRA C:2023
Posted by: Yordan Naydenov - 17-03-2025, 02:58 PM - Forum: 8.10 The essential type model - Replies (1)

Appendix C (C.1.1, p. 270 (hard copy) / p. 271 (pdf)*) of MISRA C:2023 (3rd Edn, 2nd Rev., April 2023) reads:
"... as the examples below show (si and ui are 32-bit signed and unsigned integers and u8 is an 8-bit unsigned char):"

However, there is a lack of correspondence between the above-introduced unsigned char object identifier of u8 and the naming of an operand of unsigned char type in the table that follows immediately (viz. uc, columns Expression and Notes). On page 273(274) (C.2.4, a distinct sub-section of the Appendix) such an unsigned char object of similar name is indeed used (u8a), in line with the exemplary non-specific object names used in code fragments throughout the Guidelines' body of text (the naming convention introduced on p. 14).

For the sake of ease of visually perceiving the types involved in the expressions and following through the implicit conversions they undergo, it is a good decision that concise, plain names such as si, ui, and uc are used, instead of operand identifiers cluttered with numeric characters (as would be in s32(i32), u32 and u8).

Apparently, this lack of correspondence between the operand names in the table and their prior introduction in the text is inherited from the previous versions of the Guidelines (MISRA C:2012 – 3rd Edn, March 2013; 3rd Edn, 1st Rev., February 2019). Never corrected by subsequent Technical Corrigenda or Amendments to those. It is now present in MISRA C:2025 as well.

Please, consider appending the erratum, reported in this separate forum thread, to the dedicated MISRA C Errata list maintained on the MISRA website, to keep it up-to-date and indeed a readily available single source of reference for all misprints found in MISRA C:2023, 3rd Edn, 2nd Rev.

_____

(*) Note that the text starts to disagree with the page numbering of the two documents (the electronic one and the hard copy) beginning from p. 229 onwards! This does not make favour to coherently referencing parts of the Guidelines and may lead to confusion and misunderstanding.

() This thread is considered the most relevant one as Appendix C is referenced mostly in there, and as there are no dedicated threads specifically aimed at the appendices, or some other general means for reporting typographical and other errors.

Print this item

  A3-3-2 Contradictory examples?
Posted by: cgpzs - 17-03-2025, 09:58 AM - Forum: AUTOSAR C++:2014 rules - Replies (3)

In Rule A3-3-2, there's an example with "class A" which has a non-constexpr, user-defined constructor. 

On line 31, we have a compliant example:

Code:
A instance{}; // Compliant - constant (value) initialization

However, on line 37 it's no longer compliant:

Code:
static A a{}; // Non-compliant - A’s default c’tor is not constexpr

There seems to be a contradiction here. Either the code is doing value initialization, or it's calling a constructor, but not both. Which one is it?

In other words, it seems like both examples are doing the same thing, so both should either be compliant or non-compliant. Would you agree?

Print this item

  Adopted modal expressions in guideline summaries in MISRA C as compared to MISRA C++
Posted by: Yordan Naydenov - 17-03-2025, 09:01 AM - Forum: General Questions - No Replies

There has been a discrepancy between MISRA C and MISRA C++ for some years now* concerning the modal verbs used with respect to the guideline categorization. It would be informative for the user of these Guidelines to understand what were the original reasons behind that and why this is still the case. Is it only a matter of distinct Working Groups (which nevertheless share/d some common members), has it to do with maintaining legacy, or something else entirely?

But the more concerning question is, is it planned for future MISRA C editions to adopt the more nuanced wording of the MISRA C++ Guidelines with respect to the guideline categories of "Mandatory", "Required", "Advisory", and "Disapplied"?

Currently, established convention for each of the two documents is such that a guideline is introduced through their respective summary (requirement (MISRA C) / headline (MISRA C++) text) employing one of the following modal verbs, subject to the guideline category (M/R/A/D):

  • MISRA C : "shall", "shall", "should", "should"
  • MISRA C++ : "must", "shall", "should", n/a§

A possible equalization of phrase will ultimately provide for a greater consistency between both sets of documents for the benefit of their mutual user. It would also make it straightforward for the user to unambiguously associate a guideline with its category.

_____

(*) Since introducing the category of "mandatory" in MISRA C++:2023 (October 2023), after it had been introduced in MISRA C:2012, 3rd Edn, March 2013.

() Note that guideline re-categorization entails no special treatment in this regard (e.g. substituting one modal auxiliary for another) as it is concerned only with how a guideline are to be handled and applied in a given, concrete project: compliance level claimed for a guideline may be affected due to their revised category but the normative prescription of the guideline, reclassified or not, never alters.

() MISRA C++:2008's category of "Document" ("shall") is not considered.

(§) Note that for the relatively new category of "Disapplied", introduced back in MISRA Compliance:2016 and subsequently added both in MISRA C++:2023 and recently in MISRA C:2025, only the latter actually provides any guideline with such a category. What modal expression will be adopted by future MISRA C++ editions for this fresh category is yet to be seen (could that be "ought (not) to" instead of "should (not)", to further discrimination between guidelines of different category?).

Print this item

Rainbow Roadmap to c23 support
Posted by: ACHart - 28-02-2025, 03:23 PM - Forum: General Questions - Replies (1)

Are there any formal plans/estimates/roadmaps for adding c23 support to MISRA?
If work for this has already begun, how is it going?  Smile

Print this item

  Rule 6.2.1 weak linkage
Posted by: hahn - 28-02-2025, 09:33 AM - Forum: 4.6 Basic concepts - Replies (1)

Dear MISRA group,

I have a question regarding the interpretation of the one-definition-rule in the presence of weak linkage (i.e. __attribute__((weak))).
In particular, is it considered a violation of the odr rule/rule 6.2.1 if a function with "strong" linkage "overrides" a function with "weak" linkage (as typically found in (standard) libraries)?

A special case within this discussion are global allocation and deallocation functions. The C++ standard calls them explicitly "replaceable".
Implementation-wise in any standard library I know, this is expressed by the weak linkage attribute.
Since the standard allows these few functions to be replaced explicitly, I conclude this does not constitute a violation of the one-definition-rule.

But how about any other weak-linkage function?

Thanks in advance!

Print this item

  Rule 3-4-1 and lifetimes, initialization, and side effects
Posted by: aromauld - 12-02-2025, 07:06 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

We have some interesting cases for Rule 3-4-1 which we aren't sure whether they are violations or not. Strictly adhering to the rule of reduced visibility could cause issues regarding lifetimes, initialization, and side effects of a constructor/destructor.

For instance, in the following example, is the intent to require changes to the code so that 'old_value' is not visible after the if body, or is `old_value` considered non-violating?

Code:
void fn(int a) {
    int old_value = a;
    a += 4;
    if (a > 10) {
        a = old_value;
    }
    // ...
}

Similarly, in cases where an object's constructor or destructor contains side effects, such as with a mutex, is the current visibility of 'merge_thread_lock' intended to be a violation?

Code:
void fn(int a) {
    std::unique_lock<std::shared_mutex> merge_thread_lock(global_mutex);
    if (global) {
      global = a;
      merge_thread_lock.unlock();
    }
    // ...
}

Print this item

  A8-4-5: Should have an exception for move constructors
Posted by: cgpzs - 05-02-2025, 09:45 AM - Forum: AUTOSAR C++:2014 rules - Replies (3)

Our static analyzer is complaining about our move constructor because we are not moving the entire "oth" input. Instead, we are doing member-wise move, in compliance with A12-8-1:

Code:
class B
{
public:
  B(B&& oth) : ptr(std::move(oth.ptr)) // Compliant
  {
     oth.ptr = nullptr;
  }
};

Do you agree that A8-4-5 should explicitly clarify that the rule does not apply to move constructors?

Print this item

  A7-2-1 Still relevant in C++14?
Posted by: cgpzs - 29-01-2025, 10:03 AM - Forum: AUTOSAR C++:2014 rules - Replies (1)

Rule A7-2-1 seems copied verbatim from the MISRA C++ 2008 rules. However, there's a key difference: C++14 has scoped enums. There, it is not unspecified (nor undefined) to cast an integer to the enum type when it is not any of the enumerators, since the valid range for the enum is the range of the underlying type. 

Based on that, what would be the rationale for keeping A7-2-1 in the AUTOSAR C++14 rules?

Print this item

  MISRA AC INT:2025
Posted by: misra-ac - 22-01-2025, 03:37 PM - Forum: MISRA AC resources - No Replies

This document explains the structure of, and relationships between, the MISRA Autocode Guidelines (MISRA AC) family of documents. It is based on the original version, 1.0, published in 2007. The document has undergone extensive revision to reflect the changes in the MISRA AC document family and related standards, and the advances in use and awareness of modelling and automatic code generation approaches since that time.



Attached Files
.pdf   MISRA AC INT V2.pdf (Size: 173.88 KB / Downloads: 5)
Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,237
» Latest member: mr li
» Forum threads: 1,034
» Forum posts: 2,851

Full Statistics

Online Users
There are currently 427 online users.
» 0 Member(s) | 423 Guest(s)
Applebot, Bing, Google, UptimeRobot

Latest Threads
Compiler - minimal test s...
Forum: General Questions
Last Post: delirium5223
04-09-2025, 12:16 PM
» Replies: 0
» Views: 594
named vs positional initi...
Forum: 8.9 Initialization
Last Post: delirium5223
04-09-2025, 11:27 AM
» Replies: 0
» Views: 586
Gaps in enums
Forum: General Questions
Last Post: delirium5223
04-09-2025, 11:06 AM
» Replies: 0
» Views: 308
Rule 13.3 incr/decr op in...
Forum: 8.13 Side effects
Last Post: delirium5223
04-09-2025, 10:55 AM
» Replies: 0
» Views: 278
Rule 11.6.1 - Variables i...
Forum: 4.11 Declarators
Last Post: cgpzs
02-09-2025, 11:26 AM
» Replies: 0
» Views: 726
Rule 6.8.4 clarification ...
Forum: 4.6 Basic concepts
Last Post: misra cpp
24-08-2025, 03:26 PM
» Replies: 1
» Views: 740
Rule 0.1.2 - missing exce...
Forum: 4.0 Language independent issues
Last Post: misra cpp
24-08-2025, 03:23 PM
» Replies: 1
» Views: 744
21.18 is a safe strncpy f...
Forum: 8.21 Standard libraries
Last Post: dunno
20-08-2025, 08:47 AM
» Replies: 1
» Views: 2,460
Rule 10.1.1
Forum: 4.10 Declarations
Last Post: misra cpp
08-08-2025, 01:21 PM
» Replies: 1
» Views: 769
Rule 6.7.2 variable templ...
Forum: 4.6 Basic concepts
Last Post: misra cpp
01-08-2025, 11:49 AM
» Replies: 1
» Views: 712