-
Notifications
You must be signed in to change notification settings - Fork 1.5k
check-library warns on access to a function call operator via an auto reference #4834
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
base: main
Are you sure you want to change the base?
check-library warns on access to a function call operator via an auto reference #4834
Conversation
This is probably not the right place to put that test, but I don't know any better
208037e to
9c99a8f
Compare
| " sVec.resize(1);\n" | ||
| " sVec(1).vec.resize(2);\n" | ||
| " sVec(1).vec(1) = 1.0;\n" | ||
| " S& thisS = sVec(1);\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works when using the type explicitly.
| check("template <typename T>\n" | ||
| "struct EPVector : public std::vector<T> {\n" | ||
| " using size_type = typename std::vector<T>::size_type;\n" | ||
| " [[nodiscard]] T& operator()(size_type n) { return (*this)[n - 1]; }\n" | ||
| " [[nodiscard]] const T& operator()(size_type n) const { return (*this)[n - 1]; }\n" | ||
| " void resize(size_type count) { std::vector<T>::resize(count); }\n" | ||
| "};\n" | ||
| "struct S { EPVector<double> vec; };\n" | ||
| "double f() {\n" | ||
| " EPVector<S> sVec;\n" | ||
| " sVec.resize(1);\n" | ||
| " sVec(1).vec.resize(2);\n" | ||
| " sVec(1).vec(1) = 1.0;\n" | ||
| " auto& thisS = sVec(1);\n" // NOTE: Using `auto&` instead of `S&` | ||
| " thisS.vec(2) = 2.0;\n" // TODO: --check-library: There is no matching configuration for function auto::vec() | ||
| " return sVec(1).vec(1) + thisS.vec(2);\n" // TODO: --check-library: There is no matching configuration for function auto::vec() | ||
| "}"); | ||
| ASSERT_EQUALS("", errout.str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fails.
cppcheck/test/testfunctions.cpp:2154(TestFunctions::checkFunctionCallOperatorOverrideWithAutoReference): Assertion failed.
Expected:
Actual:
[test.cpp:15]: (information) --check-library: There is no matching configuration for function auto::vec()\n
[test.cpp:16]: (information) --check-library: There is no matching configuration for function auto::vec()\n
Here's a compiler explorer link showing that the code itself is fine: https://compiler-explorer.com/z/o7d6PzK6b
|
Thank you for your contribution. We are aware of this. There's still lots of false positive Some of them are already fixed by the pending #4824 and #4826. Or are being tracked by any of the tickets in the other PR. |
I have no clue how to fix it but I noticed something so I thought I'd create a test to see if you think it's a bug and if it's fixable.
This is probably not the right place to put that test, but I don't know any better.