From ed1acc319d7fdad23a54efe6feedd0557cd98e85 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 17 Nov 2019 23:39:50 -0600 Subject: [PATCH] Fixx issue 9355: FP constParameter when returning non-const reference to struct member (#2373) --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f1cda1b5e..4fba8ebe0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1357,7 +1357,7 @@ void CheckOther::checkConstVariable() if (isVariableChanged(var, mSettings, mTokenizer->isCPP())) continue; if (Function::returnsReference(function) && - Token::findmatch(var->nameToken(), "return %varid% ;|[", scope->bodyEnd, var->declarationId())) + Token::findmatch(var->nameToken(), "return %varid% ;|[|.", scope->bodyEnd, var->declarationId())) continue; // Skip if address is taken if (Token::findmatch(var->nameToken(), "& %varid%", scope->bodyEnd, var->declarationId())) diff --git a/test/testother.cpp b/test/testother.cpp index d2b03276a..908dbe18a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1946,6 +1946,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("struct S {\n" + " int i;\n" + "};\n" + "int& f(S& s) {\n" + " return s.i;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void e();\n" "void g(void);\n" "void h(void);\n"