Skip to content

Commit e548753

Browse files
authored
Fixed #13320 (False positive: functionConst reported for method marked with &&) (danmar#7017)
1 parent 0cf639c commit e548753

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,8 @@ void CheckClass::checkConst()
21192119
continue;
21202120
if (func.functionPointerUsage)
21212121
continue;
2122+
if (func.hasRvalRefQualifier())
2123+
continue;
21222124

21232125
// don't suggest const when returning non-const pointer/reference, but still suggest static
21242126
auto isPointerOrReference = [this](const Token* start, const Token* end) -> bool {

test/testclass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class TestClass : public TestFixture {
186186
TEST_CASE(const92);
187187
TEST_CASE(const93);
188188
TEST_CASE(const94);
189+
TEST_CASE(const95); // #13320 - do not warn about r-value ref method
189190

190191
TEST_CASE(const_handleDefaultParameters);
191192
TEST_CASE(const_passThisToMemberOfOtherClass);
@@ -6705,6 +6706,14 @@ class TestClass : public TestFixture {
67056706
ASSERT_EQUALS("", errout_str());
67066707
}
67076708

6709+
void const95() { // #13320
6710+
checkConst("class C {\n"
6711+
" std::string x;\n"
6712+
" std::string get() && { return x; }\n"
6713+
"};\n");
6714+
ASSERT_EQUALS("", errout_str());
6715+
}
6716+
67086717
void const_handleDefaultParameters() {
67096718
checkConst("struct Foo {\n"
67106719
" void foo1(int i, int j = 0) {\n"

0 commit comments

Comments
 (0)