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

Username
  

Password
  





  A7-1-2: Is it really intented to mark also functions as constexpr?
Posted by: cgpzs - 28-08-2023, 09:37 AM - Forum: AUTOSAR C++:2014 rules - Replies (3)

Hi,

A7-1-2 says:
The constexpr specifier shall be used for values that can be determined at compile time.

So it only talks about "values", not "functions". However, in the example, it says the following code is not compliant, because the function Pow1 "can be" constexpr but is not marked as such:

Code:
std::int32_t Pow1(std::int32_t number)
{
    return (number * number);
}
void Fn()
{
    const std::int32_t threeSquare = Pow1(3); // Non-compliant, possible run-time evaluation
}

On the other hand, examples are not normative - the title of the rule is.

Therefore I ask: is rule A7-1-2 intended to mark every single function as constexpr if it _can_ be constexpr?

In my opinion, this has negative consequences. Constexpr-ness of a function should be a careful design decision, not something added blindly to comply with a static analysis tool. It limits the way an author can choose to implement a given function. Maybe today the function _can_ be constexpr, but tomorrow as an author I want to refactor the implementation to e.g. use more modern libraries from STL, which don't have constexpr support in C++14 (for example, a silly std::array::operator[] is not supported in constexpr functions). Changing the implementation would require removing constexpr and updating also all the clients (which could dramatically cascade into second-order functions and so on). Or the alternative would be to be locked into constexpr and have to resort to older-style code to implement it (e.g. use a C array instead of std::array), making the function ultimately less safe and violating other Autosar rules.

Thanks!

Print this item

  Rule 6-3-1: Does it also apply to "case" blocks?
Posted by: cgpzs - 24-08-2023, 12:05 PM - Forum: 6.6 Statements (C++) - Replies (1)

Consider this piece of code:

Code:
enum Foo
{
  a,
  b
};


void foo(Foo f)
{
  switch(f)
  {
    case a:
      std::cout << "a\n";
      break;
    case b:
      std::cout << "b\n";
      break;
  }

}

Is the above compliant with M6-3-1, or does one need to add braces also to the "case" blocks, e.g.:

Code:
case a:
{
  std::cout << "a\n";
  break;
}

Thanks!

Print this item

  MISRA C:2012 Rule 10.8 Clarification
Posted by: uk000032 - 14-08-2023, 01:58 PM - Forum: 8.10 The essential type model - Replies (1)

MISRA C:2012 Rule 10.8 states "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".

One example of a violation given is:

( uint32_t ) ( u16a + u16b ) /* Non-compliant - cast to wider
                              * essential type */

But what about:

( uint32_t ) u16a + ( uint32_t ) u16b  /* Compliant? */

This kind of thing does get flagged by Polyspace 2022b as a violation of Rule 10.8, but am I correct in thinking that casting the variables before the compound operator is applied means that this not in fact a violation?

Print this item

  A8-5-2 + A8-5-3: No usage of auto allowed?
Posted by: chgros - 11-08-2023, 05:36 PM - Forum: AUTOSAR C++:2014 rules - Replies (2)

It appears that it's impossible to use `auto` variables and be compliant with both A8-5-2 (which mandates {} initialization for all variables) and A8-5-3 (which forbids {} initialization for auto variables)
Is that the intention? How is one supposed to use lambdas in that case?

Print this item

  MISRA AC SLSF:2023 released
Posted by: david ward - 09-08-2023, 04:24 PM - Forum: MISRA AC SLSF discussions - No Replies

We are pleased to announce a new version of MISRA AC GMG has been released.

The MISRA Autocode (AC) family of documents deals with the application of language subsets for automatic code generation purposes. This document, MISRA AC SLSF, contains the best practices, captured as a set of design and style guidelines, for the use of The Mathworks® Simulink® and Stateflow® tools for producing models that will be used for simulation and automatic code generation. Updated in June 2023, this second edition is the current version of MISRA AC SLSF. This document supersedes the first edition (published in 2009).

The MISRA webstore provides single-user PDFs and you can purchase a hardcopy via a "print on demand" service at the following link. Please be sure to select the most appropriate “marketplace” for your location to expedite delivery. MISRA AC SLSF:2023 hardcopy

Print this item

  MISRA AC GMG:2023 released
Posted by: david ward - 09-08-2023, 04:23 PM - Forum: MISRA AC GMG discussions - Replies (2)

We are pleased to announce a new version of MISRA AC GMG has been released.

The MISRA Autocode (AC) family of documents deals with the application of language subsets for automatic code generation purposes. This document, MISRA AC GMG, contains the best practices, captured as a set of design and style guidelines, for the use in all graphical modelling environments for producing models that will be used for simulation and automatic code generation. Updated in June 2023, this second edition is the current version of MISRA AC GMG. This document supersedes the first edition (published in 2009).

The MISRA webstore provides single-user PDFs and you can purchase a hardcopy via a "print on demand" service at the following link. Please be sure to select the most appropriate “marketplace” for your location to expedite delivery. MISRA AC GMG:2023 hardcopy

Print this item

  Rule 17.3 when function has definition
Posted by: dunno - 15-06-2023, 02:32 PM - Forum: 8.17 Functions - No Replies

I wonder if the code below violates rule 17.3:

void dostuff(int x) {
    // do some stuff..
}

void func(void) {
    dostuff(12);   // <- is 17.3 violated here?
}

Please note that the functions dostuff and func violates rule 8.4 and don't have prototypes.

Question: is 17.3 violated when calling a function that violates rule 8.4?

The rationale for 17.3 also does not apply to my example code as far as I understand:

    If a function is declared implicitly, a C90 compiler will assume
    that the function has a return type of int. Since an implicit 
    function declaration does not provide a prototype, a compiler will
    have no information about the number of function parameters and
    their types. 

Print this item

  21.18 is a safe strncpy function call non-compliant?
Posted by: dunno - 15-06-2023, 01:06 PM - Forum: 8.21 Standard libraries - No Replies

I have a philosophical question.


Example code:

void foo() {
    char buf[128];
    strncpy(buf, "hello", 128);
}

The strncpy call does not have any undefined behavior. It will write "hello" in the buffer. Writing 6 bytes in a 128 byte buffer is not undefined behavior.

Does this code then violate rule 21.18? The third argument is larger than the size of the string literal.

Reading the amplification, it seems to me the code in non-compliant.

Reading the rationale, the point of this rule is to avoid buffer overflows. Since there is no buffer overflow does it mean the code is compliant?

Print this item

  MISRA Compliance Matrix
Posted by: vartika.tailor - 08-06-2023, 04:57 PM - Forum: General Questions - Replies (2)

Hi,

Please could you let me know whether I can download a template MISRA 2012 compliance matrix document and the link to the document? 

Kind regards,
Vartika

Print this item

  MISRA C:2012 Example Suite
Posted by: misra-c - 18-05-2023, 05:01 PM - Forum: MISRA resources - No Replies

For info, the MISRA C:2012 Example suite is now available via the MISRA Git Repository

https://gitlab.com/MISRA/MISRA-C/MISRA-C...mple-Suite

At the moment, this is read-only

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,205
» Latest member: domarant
» Forum threads: 1,017
» Forum posts: 2,796

Full Statistics

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

Latest Threads
Rule 7.0.5, example non-c...
Forum: 4.7 Standard conversions
Last Post: cgpzs
17-04-2025, 12:10 PM
» Replies: 0
» Views: 139
A3-3-2 Contradictory exam...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
31-03-2025, 09:30 AM
» Replies: 2
» Views: 266
16.6.1 clarification
Forum: 4.16 Overloading
Last Post: cgpzs
31-03-2025, 09:29 AM
» Replies: 2
» Views: 257
Rule 9.3.1 - iteration st...
Forum: 4.9 Statements
Last Post: misra cpp
28-03-2025, 01:17 PM
» Replies: 1
» Views: 174
Rule 8.2.8 - why aren't a...
Forum: 4.8 Expressions
Last Post: misra cpp
28-03-2025, 01:05 PM
» Replies: 1
» Views: 183
Typo in Appendix C of MIS...
Forum: 8.10 The essential type model
Last Post: Yordan Naydenov
17-03-2025, 02:58 PM
» Replies: 0
» Views: 150
Adopted modal expressions...
Forum: General Questions
Last Post: Yordan Naydenov
17-03-2025, 09:01 AM
» Replies: 0
» Views: 218
Roadmap to c23 support
Forum: General Questions
Last Post: ACHart
28-02-2025, 03:23 PM
» Replies: 0
» Views: 197
Rule 6.2.1 weak linkage
Forum: 4.6 Basic concepts
Last Post: misra cpp
28-02-2025, 01:04 PM
» Replies: 1
» Views: 252
A8-4-5: Should have an ex...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
21-02-2025, 12:58 PM
» Replies: 3
» Views: 669