Skip to content

Commit 9c99a8f

Browse files
committed
checkFunctionCallOperatorOverrideWithAutoReference
This is probably not the right place to put that test, but I don't know any better
1 parent 80050b1 commit 9c99a8f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/testfunctions.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class TestFunctions : public TestFixture {
116116
TEST_CASE(checkUseStandardLibrary12);
117117
TEST_CASE(checkUseStandardLibrary13);
118118
TEST_CASE(checkUseStandardLibrary14);
119+
120+
TEST_CASE(checkFunctionCallOperatorOverrideWithAutoReference);
119121
}
120122

121123
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -2109,6 +2111,50 @@ class TestFunctions : public TestFixture {
21092111
"}}\n");
21102112
ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout.str());
21112113
}
2114+
2115+
void checkFunctionCallOperatorOverrideWithAutoReference() {
2116+
const auto settings_old = settings;
2117+
settings.checkLibrary = true;
2118+
check("template <typename T>\n"
2119+
"struct EPVector : public std::vector<T> {\n"
2120+
" using size_type = typename std::vector<T>::size_type;\n"
2121+
" [[nodiscard]] T& operator()(size_type n) { return (*this)[n - 1]; }\n"
2122+
" [[nodiscard]] const T& operator()(size_type n) const { return (*this)[n - 1]; }\n"
2123+
" void resize(size_type count) { std::vector<T>::resize(count); }\n"
2124+
"};\n"
2125+
"struct S { EPVector<double> vec; };\n"
2126+
"double f() {\n"
2127+
" EPVector<S> sVec;\n"
2128+
" sVec.resize(1);\n"
2129+
" sVec(1).vec.resize(2);\n"
2130+
" sVec(1).vec(1) = 1.0;\n"
2131+
" S& thisS = sVec(1);\n"
2132+
" thisS.vec(2) = 2.0;\n"
2133+
" return sVec(1).vec(1) + thisS.vec(2);\n"
2134+
"}");
2135+
ASSERT_EQUALS("", errout.str());
2136+
2137+
check("template <typename T>\n"
2138+
"struct EPVector : public std::vector<T> {\n"
2139+
" using size_type = typename std::vector<T>::size_type;\n"
2140+
" [[nodiscard]] T& operator()(size_type n) { return (*this)[n - 1]; }\n"
2141+
" [[nodiscard]] const T& operator()(size_type n) const { return (*this)[n - 1]; }\n"
2142+
" void resize(size_type count) { std::vector<T>::resize(count); }\n"
2143+
"};\n"
2144+
"struct S { EPVector<double> vec; };\n"
2145+
"double f() {\n"
2146+
" EPVector<S> sVec;\n"
2147+
" sVec.resize(1);\n"
2148+
" sVec(1).vec.resize(2);\n"
2149+
" sVec(1).vec(1) = 1.0;\n"
2150+
" auto& thisS = sVec(1);\n" // NOTE: Using `auto&` instead of `S&`
2151+
" thisS.vec(2) = 2.0;\n" // TODO: --check-library: There is no matching configuration for function auto::vec()
2152+
" return sVec(1).vec(1) + thisS.vec(2);\n" // TODO: --check-library: There is no matching configuration for function auto::vec()
2153+
"}");
2154+
ASSERT_EQUALS("", errout.str());
2155+
2156+
settings = settings_old;
2157+
}
21122158
};
21132159

21142160
REGISTER_TEST(TestFunctions)

0 commit comments

Comments
 (0)