Skip to content

Commit ebf4cc2

Browse files
Fix #12626 FP returnByReference with string_view or template (#6311)
1 parent c793516 commit ebf4cc2

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/checkclass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,11 @@ void CheckClass::checkReturnByReference()
33303330
continue;
33313331
if (func.isImplicitlyVirtual())
33323332
continue;
3333+
if (func.isOperator())
3334+
continue;
3335+
if (const Library::Container* container = mSettings->library.detectContainer(func.retDef))
3336+
if (container->view)
3337+
continue;
33333338
if (const Variable* var = getSingleReturnVar(func.functionScope)) {
33343339
if (!var->valueType())
33353340
continue;

test/testclass.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8964,6 +8964,19 @@ class TestClass : public TestFixture {
89648964
checkReturnByReference("struct S { S(); };\n" // #12620
89658965
"S::S() = delete;\n");
89668966
ASSERT_EQUALS("", errout_str()); // don't crash
8967+
8968+
checkReturnByReference("struct S {\n" // #12626
8969+
" std::string s;\n"
8970+
" operator std::string_view() const { return s; }\n"
8971+
" std::string_view get() const { return s; }\n"
8972+
"};\n"
8973+
"template<typename T>\n"
8974+
"struct U {\n"
8975+
" T t;\n"
8976+
" operator const T& () const { return t; }\n"
8977+
"};\n"
8978+
"U<std::string> u;\n");
8979+
ASSERT_EQUALS("", errout_str());
89678980
}
89688981
};
89698982

0 commit comments

Comments
 (0)