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

Username
  

Password
  





  Rule 6.2.1: non-inline constexpr variables in headers?
Posted by: cgpzs - 22-11-2024, 10:11 AM - Forum: 4.6 Basic concepts - Replies (3)

Hi, 

Consider the following example:

Code:
// foo.h
constexpr int kFoo = 123;

inline int foo(int x)
{
  return x * kFoo;
}

// tu1.cpp
#include "foo.h"
int tu1() { return foo(1); }

// tu2.cpp
#include "foo.h"
int tu2() { return foo(2); }

Does the function "foo" violate Rule 6.2.1 in this context, given that kFoo is not a C++17 inline variable? 
Or would it violate 6.2.1 only if kFoo were ODR-used (for example, passed by reference)?

Thanks!

Print this item

  Rule 0.1.2
Posted by: stephanmuench - 21-11-2024, 01:12 PM - Forum: 4.0 Language independent issues - Replies (1)

Dear MISRA members,

I would have a question about MISRA C++:2023 Rule 0.1.2 which mentions in its rationale
"Overloaded operators are excluded from this rule because [...]"

Here, my question is whether in this scope, `operator()` should be considered to be a built-in operator.
Since to me, such one should instead be considered more of a normal function call.
Otherwise, it would undermine the rule's actual intention, which is to diagnose any unused return values of function calls, am I right?
Especially for modern C++ where plenty of code gets put into lambdas and/or std::function.

I would very happy if you could share some thoughts about this.

Thanks a lot in advance & best regards,
Stephan

Print this item

  A18-9-4
Posted by: cgpzs - 15-10-2024, 09:58 AM - Forum: AUTOSAR C++:2014 rules - Replies (3)

Hi!

I wonder if this code example technically violates A18-9-4?

Code:
#include <memory>

struct Foo
{
    explicit Foo(int);
};

int main()
{
    int val{};
    auto x = std::make_unique<Foo>(val);
    ++val; // non-compliant?
}

Since internally, std::make_unique takes the input arguments as "Args&&..." and std::forward's them into the constructor of the class.

Thanks!

Print this item

  MISRA 2023 Test Suite
Posted by: grigdon - 14-10-2024, 01:27 PM - Forum: General Questions - No Replies

Hi,

Is there a MISRA 2023 test suite? I'm looking for C code with violations to be used for static analysis tool validation.

Thanks

Gerry

Print this item

  MISRA C:2023 ADD4
Posted by: david ward - 11-10-2024, 07:41 PM - Forum: MISRA resources - No Replies

This Addendum to MISRA C:2023 sets out the coverage by MISRA C:2023 against the language-independent guidance of ISO/IEC 24772-1:2019 and the C language specific guidance of ISO/IEC 24772-3:2020



Attached Files
.pdf   MISRA C 2023 ADD4.pdf (Size: 364.7 KB / Downloads: 14)
Print this item

  MISRA C:2023 ADD2
Posted by: david ward - 11-10-2024, 07:40 PM - Forum: MISRA resources - No Replies

This Addendum to MISRA C:2023 sets out the coverage by MISRA C:2023 against ISO/IEC 17961, incorporating the 2016 technical corrigendum to the latter document.



Attached Files
.pdf   MISRA C 2023 ADD2.pdf (Size: 285.63 KB / Downloads: 9)
Print this item

  Rule 7.0.2: operator const char *()
Posted by: karos - 11-10-2024, 12:33 PM - Forum: 4.7 Standard conversions - Replies (2)

Hello,

Rule 7.0.2 has an exception for converting pointer to bool, and requires an explicit operator bool() for classes. But what if a class, let's say a wrapper class for strings, provides an operator const char *? Consider the following example:

Code:
class C
{
public:
    operator const char *() const;
};

void f(C c)
{
    if (c); // C is converted twice: C -> const char * -> bool
}

Shall the commented line be considered compliant with this rule (because each of the conversion steps by itself is compliant), or not (because as a whole it is the conversion of a class to bool without using an explicit operator bool)?

Print this item

  A8-4-5: are partial moves allowed?
Posted by: cgpzs - 01-10-2024, 12:28 PM - Forum: AUTOSAR C++:2014 rules - Replies (1)

Are partial moves allowed by A8-4-5? If not, why not?

For example, consider the following snippet from Effective Modern C++ (Meyers), Item 25, page 169:

Code:
class Widget {
public:
   Widget(Widget&& rhs)
   : name(std::move(rhs.name)),
     p(std::move(rhs.p))
   { … }
   …

// rhs is rvalue reference
private:
   std::string name;
   std::shared_ptr<SomeDataStructure> p;
};

Print this item

  Does Directive 5.7.2 apply to #elif directives?
Posted by: rg99 - 30-09-2024, 09:29 PM - Forum: 4.5 Lexical conventions - Replies (1)

Is the following intended to be compliant with 5.7.2?

Code:
#if 1
/* some code */
#elif 0
/* some code */
#endif

Presumably this is just as offensive to the spirit of 5.7.2 as #if 0 is but an official position would be appreciated as the Directive only actually mentions #if.

Print this item

  is a cast compliant with Rule 12.4
Posted by: sowisojh - 30-09-2024, 08:25 AM - Forum: 8.12 Expressions - No Replies

Is the cast in the following code compliant with MISRA2023 Rule 12.4, assuming a machine having int as 32 bit?


Code:
#include <stdint.h>

#define USEFUL_BIT ((uint16_t)0x0020u)

uint16_t clear_useful_bit(uint16_t bitmask)
{
  uint16_t cleared_mask = bitmask;

  cleared_mask &= (uint16_t)~USEFUL_BIT;

  return cleared_mask;
}

According to Appendix D.7.5 1.1 the result of ~ is the UTRL of the result. Assuming an 32 bit integer machine this would be 4294967263u. The result of the cast to uint16_t would be perform a "repeatedly [...] subtracting one more than the maximum value that can be represented in the new type until the value is in the new type" which leads to 65503.

Is this type conversion treated as "unsigned integer wrap-around" in the sense of Rule 12.4 ?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,195
» Latest member: m4marshal
» Forum threads: 1,008
» Forum posts: 2,778

Full Statistics

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

Latest Threads
A8-4-5: Should have an ex...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
49 minutes ago
» Replies: 1
» Views: 78
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
1 hour ago
» Replies: 3
» Views: 1,132
Rule 3-4-1 and lifetimes,...
Forum: 6.3 Basic concepts (C++)
Last Post: misra cpp
1 hour ago
» Replies: 1
» Views: 48
Application of Rule 15.0....
Forum: 4.15 Special member functions
Last Post: misra cpp
07-02-2025, 12:44 PM
» Replies: 3
» Views: 2,508
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: misra cpp
07-02-2025, 12:43 PM
» Replies: 3
» Views: 670
A7-2-1 Still relevant in ...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
31-01-2025, 01:20 PM
» Replies: 1
» Views: 178
MISRA AC INT:2025
Forum: MISRA AC resources
Last Post: misra-ac
22-01-2025, 03:37 PM
» Replies: 0
» Views: 129
MISRA AC SLSF:2023 AMD3
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
13-01-2025, 10:58 AM
» Replies: 0
» Views: 174
MISRA AC SLSF:2023 AMD3
Forum: MISRA AC resources
Last Post: misra-ac
13-01-2025, 10:57 AM
» Replies: 0
» Views: 164
Rule 7.0.4 - exception fo...
Forum: 4.7 Standard conversions
Last Post: misra cpp
10-01-2025, 02:26 PM
» Replies: 4
» Views: 756