Skip to content

Commit 3f50540

Browse files
Fix #11432 FP passedByValue for overriden function (#4632)
1 parent 7aae78f commit 3f50540

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ void CheckOther::checkPassByReference()
13321332
}
13331333

13341334
// Check if variable could be const
1335-
if (!var->scope() || var->scope()->function->hasVirtualSpecifier())
1335+
if (!var->scope() || var->scope()->function->isImplicitlyVirtual())
13361336
continue;
13371337

13381338
if (canBeConst(var, mSettings)) {

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,15 @@ class TestOther : public TestFixture {
19701970
"int* f(U u) { return u.b; }\n");
19711971
ASSERT_EQUALS("", errout.str());
19721972

1973+
check("struct B { virtual int f(std::string s) = 0; };\n" // #11432
1974+
"struct D1 : B {\n"
1975+
" int f(std::string s) override { s += 'a'; return s.size(); }\n"
1976+
"}\n"
1977+
"struct D2 : B {\n"
1978+
" int f(std::string s) override { return s.size(); }\n"
1979+
"}\n");
1980+
ASSERT_EQUALS("", errout.str());
1981+
19731982
Settings settings1;
19741983
settings1.platform(Settings::Win64);
19751984
check("using ui64 = unsigned __int64;\n"

0 commit comments

Comments
 (0)