필터 지우기
필터 지우기

Polyspace-bug-finder raises issue due to Rule A3-1-5 if inline function is declared in source file

조회 수: 2 (최근 30일)
Hello,
I declared a function in the header file and implemented it in the source file using the "inline" keyword. Polyspace-bug-finder still raises an issue because of Autosar rule A3-1-5.
Is this intended so that the function definition shall be placed in the header file?
Thanks!

채택된 답변

Anirban
Anirban 2023년 7월 27일
Can you show a small reproduction example? Also, which release are you using?
For instance, there is no violation of A3-1-5 in this example on the inline definition of A::Bar() :
classDefs.h:
class A
{
private:
std::uint32_t val = 5;
public:
inline std::uint32_t Foo() //Compliant
{
return val;
}
std::uint32_t Bar();
};
C++ file:
#include <cstdint>
#include <iostream>
#include "classDefs.h"
inline std::uint32_t A::Bar()
{
int updatedVal = val + 5;
return (updatedVal);
}
std::uint32_t main()
{
A a;
std::cout << a.Foo() << std::endl;
std::cout << a.Bar() << std::endl;
return 0;
}

추가 답변 (1개)

Viktoria
Viktoria 2023년 7월 28일
Hi Anirban,
thanks for the answer and the code example.
Following modification of the exmaple will result in a violation of rule A3-1-5 in A::Foo().
classDefs.h
#pragma once
#include <cstdint>
class A {
private:
std::uint32_t val = 5;
public:
std::uint32_t Foo();
std::uint32_t Bar();
};
classDefs.cpp
#include "classDefs.h"
#include <iostream>
std::uint32_t A::Bar() {
int updatedVal = val + 5;
return (updatedVal);
}
inline std::uint32_t A::Foo()
{
return val;
}
std::uint32_t main() {
A a;
std::cout << a.Foo() << std::endl;
std::cout << a.Bar() << std::endl;
return 0;
}
Used polyspace version: R2022a
  댓글 수: 2
Anirban
Anirban 2023년 8월 7일
Thanks for the reproduction! Yes, the checker is intended to work this way. The specs for AUTOSAR C++14 A3-1-5 suggest placing the definitions of small methods inside the class definition to save time and space (and the checker treats one-line functions as "small methods"). So, in the above example, placing the method definition inside the class definition would be the fix for the coding rule violation.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by