Skip to content

Conversation

@jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Feb 28, 2023

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.

This is probably not the right place to put that test, but I don't know any better
@jmarrec jmarrec force-pushed the checkFunctionCallOperatorOverrideWithAutoReference branch from 208037e to 9c99a8f Compare February 28, 2023 10:11
" sVec.resize(1);\n"
" sVec(1).vec.resize(2);\n"
" sVec(1).vec(1) = 1.0;\n"
" S& thisS = sVec(1);\n"
Copy link
Contributor Author

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.

Comment on lines +2137 to +2154
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());
Copy link
Contributor Author

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

@firewave
Copy link
Collaborator

firewave commented Feb 28, 2023

Thank you for your contribution.

We are aware of this. There's still lots of false positive --check-library warnings in our own code base - see #3082 about enabling those in our CI and fixing them.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants