You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testclass.cpp
+40Lines changed: 40 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -188,6 +188,7 @@ class TestClass : public TestFixture {
188
188
TEST_CASE(const94);
189
189
TEST_CASE(const95); // #13320 - do not warn about r-value ref method
190
190
TEST_CASE(const96);
191
+
TEST_CASE(const97);
191
192
192
193
TEST_CASE(const_handleDefaultParameters);
193
194
TEST_CASE(const_passThisToMemberOfOtherClass);
@@ -6723,6 +6724,45 @@ class TestClass : public TestFixture {
6723
6724
ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Either there is a missing 'override', or the member function 'S::f' can be const.\n", errout_str());
6724
6725
}
6725
6726
6727
+
voidconst97() { // #13301
6728
+
checkConst("struct S {\n"
6729
+
" std::vector<int> v;\n"
6730
+
" int f() {\n"
6731
+
" const int& r = v.front();\n"
6732
+
" return r;\n"
6733
+
" }\n"
6734
+
" int g() {\n"
6735
+
" const int& r = v.at(0);\n"
6736
+
" return r;\n"
6737
+
" }\n"
6738
+
" void h() {\n"
6739
+
" if (v.front() == 0) {}\n"
6740
+
" if (1 == v.front()) {}\n"
6741
+
" }\n"
6742
+
" void i() {\n"
6743
+
" v.at(0) = 0;\n"
6744
+
" }\n"
6745
+
" void j() {\n"
6746
+
" dostuff(1, v.at(0));\n"
6747
+
" }\n"
6748
+
" void k() {\n"
6749
+
" int& r = v.front();\n"
6750
+
" r = 0;\n"
6751
+
" }\n"
6752
+
"};\n");
6753
+
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'S::f' can be const.\n"
6754
+
"[test.cpp:7]: (style, inconclusive) Technically the member function 'S::g' can be const.\n"
6755
+
"[test.cpp:11]: (style, inconclusive) Technically the member function 'S::h' can be const.\n",
6756
+
errout_str());
6757
+
6758
+
checkConst("struct B { std::string s; };\n"
6759
+
"struct D : B {\n"
6760
+
" bool f(std::string::iterator it) { return it == B::s.begin(); }\n"
6761
+
"};\n");
6762
+
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'D::f' can be const.\n",
0 commit comments