From 9c99a8f6eeeaf5a26f897d6c524020f0ce2df8fb Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Tue, 28 Feb 2023 11:01:53 +0100 Subject: [PATCH] checkFunctionCallOperatorOverrideWithAutoReference This is probably not the right place to put that test, but I don't know any better --- test/testfunctions.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index ba9b628faf1..494d801489c 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -116,6 +116,8 @@ class TestFunctions : public TestFixture { TEST_CASE(checkUseStandardLibrary12); TEST_CASE(checkUseStandardLibrary13); TEST_CASE(checkUseStandardLibrary14); + + TEST_CASE(checkFunctionCallOperatorOverrideWithAutoReference); } #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) @@ -2109,6 +2111,50 @@ class TestFunctions : public TestFixture { "}}\n"); ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::memset instead of loop.\n", errout.str()); } + + void checkFunctionCallOperatorOverrideWithAutoReference() { + const auto settings_old = settings; + settings.checkLibrary = true; + check("template \n" + "struct EPVector : public std::vector {\n" + " using size_type = typename std::vector::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::resize(count); }\n" + "};\n" + "struct S { EPVector vec; };\n" + "double f() {\n" + " EPVector sVec;\n" + " sVec.resize(1);\n" + " sVec(1).vec.resize(2);\n" + " sVec(1).vec(1) = 1.0;\n" + " S& thisS = sVec(1);\n" + " thisS.vec(2) = 2.0;\n" + " return sVec(1).vec(1) + thisS.vec(2);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("template \n" + "struct EPVector : public std::vector {\n" + " using size_type = typename std::vector::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::resize(count); }\n" + "};\n" + "struct S { EPVector vec; };\n" + "double f() {\n" + " EPVector 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()); + + settings = settings_old; + } }; REGISTER_TEST(TestFunctions)