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

Username
  

Password
  





  5-2-10 with non-arithmetic operators
Posted by: Tobias Loose - 05-04-2022, 12:34 PM - Forum: 6.5 Expressions (C++) - Replies (1)

Hi!

The rule states 


Quote:The increment (++) and decrement (--) operators should not be mixed with other operators in an expression.


The code checker we employ also flags the usage of these operators in expressions that contain member-access operators, subscript operators, and the like.

The rationale and example appear to focus on other arithmetic operators, which makes sense.

Is this an oversight in the rule formulation (missing "arithmetic"), or is the following intentionally non-compliant with 5-2-10?

Code:
void foo()
{
    struct A { int b; };

    A a{0};

    a.b++; // Non-compliant

    int c[3] = {1, 2, 3};

    c[2]++; // Non-compliant

    A* const a_ptr = &a;

    a_ptr->b++; // Non-compliant
}

Thanks!

Print this item

  Rule 5-0-6 about underlying type of boolean bit field
Posted by: zhaohui - 01-04-2022, 09:08 AM - Forum: 6.5 Expressions (C++) - Replies (1)

Quote:Rule 5–0–6 (Required) An implicit integral or floating-point conversion shall not reduce the size of the underlying type.

Refer to the Bit-field operands part of determination of the underlying type of an expression
Quote:Bit-field objects have an underlying type equivalent to an integral type of a size determined by their width. For example, a bit-field with width n, will have the same underlying type as a fundamental type with the same sign and width (if one exists).

However, for one bit field, there's no any fundamental type with only one bit.
So what exactly are bitAs' and bitBs' underlying types? Please help to clarify, thanks.

Code:
struct
{
    bool bitA : 1;
    int  bitB : 1;
} boolbitfield;

int main()
{
    bool b = boolbitfield.bitA; // compliant or non-compliant?
}

Print this item

  A16-0-1 Use #define for conditional file inclusion?
Posted by: cgpzs - 25-03-2022, 01:57 PM - Forum: AUTOSAR C++:2014 rules - Replies (3)

Hi,

It's not clear if A16-0-1 allows using #define exclusively for creating header guards, or also for conditional file inclusion. Could you comment on that?

Example:

Code:
// foo.h
#if defined (SOMETHING) && !defined (SOMETHING_ELSE)  // Complex logic that we don't want to repeat everywhere
  #define SHOULD_INCLUDE_A              // Violating A16-0-1?
#else
  #define SHOULD_INCLUDE_B              // Violating A16-0-1?
#endif

// bar.h
#if   defined (SHOULD_INCLUDE_A)
  #include "bar_a.h"
#elif defined (SHOULD_INCLUDE_B)
  #include "bar_b.h"
#endif

// baz.h
#if   defined (SHOULD_INCLUDE_A)
  #include "baz_a.h"
#elif defined (SHOULD_INCLUDE_B)
  #include "baz_b.h"
#endif

Thanks!

Print this item

  Rule M7-3-4 and UDLs
Posted by: davebrown - 18-03-2022, 01:27 PM - Forum: AUTOSAR C++:2014 rules - Replies (3)

When using UDLs like the ones provided by std::chrono, for example, we get a violation of rule M7-3-4 when including the UDL namespace:

Code:
using namespace std::chrono_literals; // <- violation here

Naturally, this rule was written before UDLs were a thing and so it's inevitably not designed for this use case.

We have discussed two options for this:
  1. Partially deviate for this use case only
  2. Explicitly import the required UDL(s)
The first option is probably okay if we can limit the scope sufficiently but someone has to write it and defend it.
The second option requires writing code similar to:
Code:
using std::chrono_literals::operator""s;
using std::chrono_literals::operator""ms;
which is a little cumbersome, especially for developers unfamiliar with how a UDL is written.

What I would like to know is how MISRA intends to handle UDLs in the upcoming guidelines? If they are allowed, how should they be imported for convenient use? Will M7-3-4 be updated to include an exception for namespaces that define UDLs?

Thank you in advance for you time.

/Dave

Print this item

  A12-4-1 - Does it apply to private inheritance?
Posted by: cgpzs - 15-03-2022, 12:59 PM - Forum: AUTOSAR C++:2014 rules - Replies (4)

Hi,

Rule A12-4-1 says:
"Destructor of a base class shall be public virtual, public override or protected non-virtual."

Does it apply in the context of private inheritance? In that case, it's not possible to obtain a pointer to the Base class, therefore mitigating the risks the rule is trying to prevent from.


Code:
class Base  // A12-4-1 violated here?
{};

class Derived final : private Base
{};

The goal here is to be able to create both Base and Derived objects; therefore Base cannot have a protected non-virtual destructor. A public virtual destructor would come with performance penalties.

Thanks!

Print this item

  final means "final"
Posted by: kent.dorfman766 - 14-03-2022, 06:18 PM - Forum: AUTOSAR C++:2014 rules - Replies (7)

Is there some hidden silliness in the spec that requires virtual methods to be declared final when the class itself is already final?  It would be redundant if so, or is my violation warning something I need to take up with the provider of our code scanner, because they got it wrong?

Print this item

  forum thread header table is wrong
Posted by: kent.dorfman766 - 14-03-2022, 06:14 PM - Forum: AUTOSAR C++:2014 rules - Replies (1)

This forum is broken in my browser.  The thread header table is stuck at only about 25% of the screen width, while the other forum areas don't suffer that.  Smells like someone embedded problematic text in a thread title and the browser can't deal with it

Print this item

  std::exception is not a catch-all
Posted by: kent.dorfman766 - 13-03-2022, 06:40 AM - Forum: AUTOSAR C++:2014 rules - Replies (1)

This is a catch-all

try {;} catch(...) {;}

This is not

try {;} catch(std::exception&) {;}

Our validation tool incorrectly triggers the second case as an embedded catch-all violation in a submodule.

Anyone care to debate?

My take is that the rule checker was implemented by python/java folks who think c++ follows the concept of a base exception class.  It does not, since in c++ any type can be an exception parameter.

FWIW, my design heavily leverages c++ shared library .so inclusions which violate autosar eight from sunday even without the erroneous flag.

Print this item

  RTE call
Posted by: kprzygoda - 10-03-2022, 11:21 AM - Forum: 7.1 The implementation - Replies (1)

Hi All, I am calling RTE functions using microsar sip tools from vector and getting MISRA C 2012 rules violation:
1) The expression (vspSoundActivation_temp = Rte_CtApNvmWrapper_NV_VSPCfgParameters.VSP_SOUNDACTIVATIONTEMP_CF) , 0 uses the comma operator
2) The value returned by the assignment operator in vspSoundActivation_temp = Rte_CtApNvmWrapper_NV_VSPCfgParameters.VSP_SOUNDACTIVATIONTEMP_CF is being used

Is there any clear way of get rid of the messages?

Print this item

  unused enum constant
Posted by: kprzygoda - 10-03-2022, 11:16 AM - Forum: 7.1 The implementation - Replies (1)

I have created enum constant and using it only for assigment to uint8_t or if comparison of uint8_t to this constant, coverity from synopsys configured for MISRA C 2012 is generating rule violation: Type has tag xxxx_enum but that tag is never used. Is there any clear way of get rid of this message?

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,122
» Latest member: AnthonyLFN
» Forum threads: 967
» Forum posts: 2,657

Full Statistics

Online Users
There are currently 107 online users.
» 0 Member(s) | 106 Guest(s)
Bing

Latest Threads
10.2.3 Amplification
Forum: 4.10 Declarations
Last Post: hahn
Yesterday, 08:57 AM
» Replies: 2
» Views: 278
A13-5-4 opposite operator...
Forum: AUTOSAR C++:2014 rules
Last Post: aromauld
26-04-2024, 03:34 PM
» Replies: 0
» Views: 198
C++17 [[fallthrough]]; at...
Forum: 6.6 Statements (C++)
Last Post: mshawa
22-04-2024, 06:29 PM
» Replies: 0
» Views: 201
cvalue and constant integ...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
19-04-2024, 04:53 PM
» Replies: 1
» Views: 265
Rule 6-2-3 and C++17 [[fa...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
19-04-2024, 04:48 PM
» Replies: 1
» Views: 227
Rule 7.0.5 Example potent...
Forum: 4.7 Standard conversions
Last Post: misra cpp
12-04-2024, 01:54 PM
» Replies: 1
» Views: 210
Rule 0.2.4 non-compliant ...
Forum: 4.0 Language independent issues
Last Post: misra cpp
12-04-2024, 01:51 PM
» Replies: 1
» Views: 245
Further guidance on MISRA...
Forum: 8.10 The essential type model
Last Post: mshawa
09-04-2024, 02:29 PM
» Replies: 0
» Views: 167
MISRA AC SLSF:2023 AMD1
Forum: MISRA AC resources
Last Post: david ward
05-04-2024, 01:56 PM
» Replies: 0
» Views: 188
MISRA AC GMG:2023 release...
Forum: MISRA AC GMG discussions
Last Post: misra-ac
25-03-2024, 06:01 PM
» Replies: 2
» Views: 578