Skip to content

Commit cc527b1

Browse files
authored
Merge pull request #62 from mbaluda-org/issue11-A13-2-2
Issue 11: A13-2-2 distinguish stream operators from binary shift
2 parents 5ba5f3a + eb5616d commit cc527b1

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A13-2-2` - `BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql`:
2+
- Remove findings related to stream operators.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| test.cpp:16:9:16:17 | operator- | User-defined bitwise or arithmetic operator operator-(const A &, int) -> const A does not return a prvalue. |
22
| test.cpp:20:4:20:12 | operator\| | User-defined bitwise or arithmetic operator operator\|(const A &, const A &) -> A * does not return a prvalue. |
3-
| test.cpp:29:6:29:14 | operator+ | User-defined bitwise or arithmetic operator NS_C::operator+(const C &, const C &) -> int & does not return a prvalue. |
3+
| test.cpp:24:9:24:18 | operator<< | User-defined bitwise or arithmetic operator operator<<(const A &, const A &) -> const A does not return a prvalue. |
4+
| test.cpp:34:6:34:14 | operator+ | User-defined bitwise or arithmetic operator NS_C::operator+(const C &, const C &) -> int & does not return a prvalue. |

cpp/autosar/test/rules/A13-2-2/test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ A *operator|(A const &a1, A const &a2) noexcept { // NON_COMPLIANT
2121
return new A();
2222
}
2323

24+
const A operator<<(A const &, A const &) noexcept // NON_COMPLIANT
25+
{
26+
return A{};
27+
}
28+
2429
class C {
2530
C &operator=(const C &rhs);
2631
};
@@ -31,3 +36,10 @@ int &operator+(const C &lhs, const C &rhs) { // NON_COMPLIANT
3136
return slocal;
3237
}
3338
} // namespace NS_C
39+
40+
#include <iostream>
41+
struct Test {};
42+
std::ostream &operator<<(std::ostream &os, const Test &) { // COMPLIANT
43+
os << "test";
44+
return os;
45+
}

cpp/common/src/codingstandards/cpp/Operator.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class UserBitwiseOperator extends Function {
170170
op in ["&", "|", "^", "~", "%", "<<", ">>"]
171171
) and
172172
not this.isCompilerGenerated() and
173-
not this.getType().hasName("ostream") and
174-
not this.getType().hasName("istream")
173+
not this.getType().(ReferenceType).getBaseType().hasName("ostream") and
174+
not this.getType().(ReferenceType).getBaseType().hasName("istream")
175175
}
176176
}
177177

cpp/common/test/includes/standard-library/ostream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _GHLIBCPP_OSTREAM
22
#define _GHLIBCPP_OSTREAM
33
#include "string.h"
4+
#include <ios>
45

56
namespace std {
67
template <class charT, class traits>

0 commit comments

Comments
 (0)