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

Username
  

Password
  





  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

  M9-3-1 and std::span-like classes
Posted by: cgpzs - 18-02-2022, 09:42 AM - Forum: 6.9 Classes (C++) - Replies (3)

Hi,

Our static analyzer is reporting a violation of M9-3-1 in the following backport of C++20's `std:Confusedpan`:

Code:
template <typename T>
class Span
{
public:
   Span(T* const ptr, std::size_t size) :
      data_{ptr},
      size_{size}
   {}

T* data() const { return data_; }  // M9-3-1 reported here

private:
   T* data_;
   std::size_t size_;
};

int main()
{
    std::array<int, 3> arr{1,2,3};
    Span<int> s{arr.data(), arr.size()};
}


The `Span` class is merely a non-owning wrapper around a memory buffer. Furthermore, the `data()` function is not returning a reference to any class member, it's returning a copy of a class member. 

Would you say M9-3-1 is violated in this example?

Thanks!

Print this item

  M5-0-15 + range-based for loops
Posted by: cgpzs - 15-02-2022, 12:25 PM - Forum: 6.5 Expressions (C++) - Replies (3)

Hi,

Our static analyzer is reporting M5-0-15 "this is using pointer arithmetic" in the following code:

Code:
int x[3] = {1,2,3};

int z = 0;
for (int y : x)  // M5-0-15 reported here
{
    z += y;
}

Most likely due to the range-based for loop expanding to an iterator-based for loop.

However, we would argue the MISRA rules apply to code written by users, not code generated by the compiler behind the scenes. 

What do you think, is the above code violating M5-0-15?

Thanks!

Print this item

  Side effects in floating point comparisons
Posted by: gdavis - 13-01-2022, 09:27 PM - Forum: 8.13 Side effects - Replies (1)

Hello,

A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:

int in_range(double a)
{
    int result = 0;
    if (a >= 10.0 && a <= 20.0) {
        result = 1;
    }
    return result;
}

The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects.  See the footnote in C99 5.1.2.3.


This kind of goes back to Directive 1.1 and various decisions about floating point.

Does everyone agree that this should be considered a violation?  I would appreciate any other thoughts you may have.

Thanks,

-Greg

Print this item

  A20-8-6
Posted by: martin.m.dowie - 12-01-2022, 09:35 AM - Forum: AUTOSAR C++:2014 rules - Replies (1)

What is the preferred method of assigning to a local member data of type std::shared_ptr<T>?

Given the code below, are the lines indicated as A20-8-6 non-compliant really so and why? We can understand C2 (types match exactly). We can understand C4 (types match exactly and the member data is of std::shared_ptr<T>&.

The class C1 we believe is non-compliant but we can't justify ourselves of the reason why.

Is the rule trying to enforce 3 e) from GoTW #91 (https://herbsutter.com/2013/06/05/gotw-9...arameters/)?

Code:
struct S {};

class C1 {
    std::shared_ptr<S> s;
public:
    C1(const std::shared_ptr<S>& aS) : s(aS) {} // A20-8-6 non-compliant
};

class C2 {
    std::shared_ptr<S> s;
public:
    C2(std::shared_ptr<S> aS) : s(aS) {} // OK
};

class C3 {
    std::shared_ptr<S> s;
public:
    C3(std::shared_ptr<S>& aS) : s(aS) {} // A20-8-6 non-compliant
};

class C4 {
    const std::shared_ptr<S>& s;
public:
    C4(const std::shared_ptr<S>& aS) : s(aS) {} // OK
};

void f () {
    auto s = std::make_shared<S>();
    C1 c1(std::make_shared<S>());
    C2 c2(std::make_shared<S>());
    C3 c3(s);
    C4 c4(std::make_shared<S>());
}

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,171
» Latest member: stephanmuench
» Forum threads: 997
» Forum posts: 2,751

Full Statistics

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

Latest Threads
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
7 hours ago
» Replies: 0
» Views: 17
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 351
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 309
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,432
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,846
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,469
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,673
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,230
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 405
MISRA 2023 Test Suite
Forum: General Questions
Last Post: grigdon
14-10-2024, 01:27 PM
» Replies: 0
» Views: 182