Skip to content

Commit

Permalink
Fix #12626 FP returnByReference with string_view or template
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 20, 2024
1 parent 1fa728c commit f9d31a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,11 @@ void CheckClass::checkReturnByReference()
continue;
if (func.isImplicitlyVirtual())
continue;
if (func.isOperator())
continue;
if (const Library::Container* container = mSettings->library.detectContainer(func.retDef))
if (container->view)
continue;
if (const Variable* var = getSingleReturnVar(func.functionScope)) {
if (!var->valueType())
continue;
Expand Down
13 changes: 13 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8955,6 +8955,19 @@ class TestClass : public TestFixture {
checkReturnByReference("struct S { S(); };\n" // #12620
"S::S() = delete;\n");
ASSERT_EQUALS("", errout_str()); // don't crash

checkReturnByReference("struct S {\n" // #12626
" std::string s;\n"
" operator std::string_view() const { return s; }\n"
" std::string_view get() const { return s; }\n"
"};\n"
"template<typename T>\n"
"struct U {\n"
" T t;\n"
" operator const T& () const { return t; }\n"
"};\n"
"U<std::string> u;\n");
ASSERT_EQUALS("", errout_str());
}
};

Expand Down

0 comments on commit f9d31a7

Please sign in to comment.