Skip to content

Commit

Permalink
Fix simplification of operator->
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 10, 2023
1 parent 8a14ac3 commit a0761ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9778,7 +9778,7 @@ void Tokenizer::simplifyOperatorName()
if (par->str() == "," && !op.empty())
break;
if (!(Token::Match(par, "<|>") && !op.empty())) {
op += par->str();
op += par->str() == "." ? par->originalName() : par->str();
par = par->next();
done = false;
}
Expand Down
9 changes: 4 additions & 5 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6287,8 +6287,7 @@ class TestClass : public TestFixture {
" P<A> p;\n"
" void g() { p->f(); }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:11]: (style, inconclusive) Technically the member function 'S::g' can be const.\n",
errout.str());
ASSERT_EQUALS("", errout.str());

checkConst("struct A {\n"
" void f(int) const;\n"
Expand All @@ -6302,7 +6301,7 @@ class TestClass : public TestFixture {
" P<A> p;\n"
" void g() { p->f(1); }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:11]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", errout.str());
ASSERT_EQUALS("", errout.str());

checkConst("struct A {\n"
" void f(void*) const;\n"
Expand All @@ -6319,7 +6318,7 @@ class TestClass : public TestFixture {
" P<A> p;\n"
" std::vector<S> g() { p->f(nullptr); return {}; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:14]: (style, inconclusive) Technically the member function 'S::g' can be const.\n", errout.str());
ASSERT_EQUALS("", errout.str());

checkConst("struct A {\n"
" void f();\n"
Expand Down Expand Up @@ -8370,7 +8369,7 @@ class TestClass : public TestFixture {
"struct TPtr : public SPtr {\n"
" T* operator->() const { return (T*)p; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'operator.' overrides a function in a base class but is not marked with a 'override' specifier.\n",
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'operator->' overrides a function in a base class but is not marked with a 'override' specifier.\n",
errout.str());
}

Expand Down
2 changes: 1 addition & 1 deletion test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4950,7 +4950,7 @@ class TestTokenizer : public TestFixture {
const char code[] = "void f() {"
"static_cast<ScToken*>(xResult.operator->())->GetMatrix();"
"}";
const char result[] = "void f ( ) { static_cast < ScToken * > ( xResult . operator. ( ) ) . GetMatrix ( ) ; }";
const char result[] = "void f ( ) { static_cast < ScToken * > ( xResult . operator-> ( ) ) . GetMatrix ( ) ; }";
ASSERT_EQUALS(result, tokenizeAndStringify(code));
}

Expand Down

0 comments on commit a0761ec

Please sign in to comment.