Skip to content

Issue 11: A13-2-2 distinguish stream operators from binary shift #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2022-08-17-fix-reported-fp-for-a13-2-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A13-2-2` - `BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql`:
- Remove findings related to stream operators.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| test.cpp:16:9:16:17 | operator- | User-defined bitwise or arithmetic operator operator-(const A &, int) -> const A does not return a prvalue. |
| test.cpp:20:4:20:12 | operator\| | User-defined bitwise or arithmetic operator operator\|(const A &, const A &) -> A * does not return a prvalue. |
| 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. |
| 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. |
| 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. |
12 changes: 12 additions & 0 deletions cpp/autosar/test/rules/A13-2-2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ A *operator|(A const &a1, A const &a2) noexcept { // NON_COMPLIANT
return new A();
}

const A operator<<(A const &, A const &) noexcept // NON_COMPLIANT
{
return A{};
}

class C {
C &operator=(const C &rhs);
};
Expand All @@ -31,3 +36,10 @@ int &operator+(const C &lhs, const C &rhs) { // NON_COMPLIANT
return slocal;
}
} // namespace NS_C

#include <iostream>
struct Test {};
std::ostream &operator<<(std::ostream &os, const Test &) { // COMPLIANT
os << "test";
return os;
}
4 changes: 2 additions & 2 deletions cpp/common/src/codingstandards/cpp/Operator.qll
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class UserBitwiseOperator extends Function {
op in ["&", "|", "^", "~", "%", "<<", ">>"]
) and
not this.isCompilerGenerated() and
not this.getType().hasName("ostream") and
not this.getType().hasName("istream")
not this.getType().(ReferenceType).getBaseType().hasName("ostream") and
not this.getType().(ReferenceType).getBaseType().hasName("istream")
}
}

Expand Down
1 change: 1 addition & 0 deletions cpp/common/test/includes/standard-library/ostream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _GHLIBCPP_OSTREAM
#define _GHLIBCPP_OSTREAM
#include "string.h"
#include <ios>

namespace std {
template <class charT, class traits>
Expand Down