Skip to content

Commit e129ca0

Browse files
dmcppcheckclaude
andcommitted
simplifyUsing: only skip destructor names, not unary bitwise not
The name after "~" was never replaced, which also affected expressions like "~U(0)" where U is a type alias. Limit the check to "~ %name% ( )". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c16acbf commit e129ca0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎lib/tokenize.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ namespace {
28212821
}
28222822

28232823
// destructor name, i.e. "~C" in "~C()" or "N::C::~C()"
2824-
if (tok1->strAt(-1) == "~")
2824+
if (Token::Match(tok1->previous(), "~ %name% ( )"))
28252825
return false;
28262826

28272827
// Inside a class the unqualified class name is the injected-class-name,

‎test/testsimplifyusing.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class TestSimplifyUsing : public TestFixture {
8383
TEST_CASE(simplifyUsing43);
8484
TEST_CASE(simplifyUsing44);
8585
TEST_CASE(simplifyUsing45);
86+
TEST_CASE(simplifyUsing46);
8687

8788
TEST_CASE(simplifyUsing8970);
8889
TEST_CASE(simplifyUsing8971);
@@ -1069,6 +1070,15 @@ class TestSimplifyUsing : public TestFixture {
10691070
ASSERT_EQUALS("", errout_str());
10701071
}
10711072

1073+
void simplifyUsing46() {
1074+
// alias after unary bitwise not must be replaced
1075+
const char code[] = "using U = unsigned char;\n"
1076+
"unsigned f() { return ~U(0) & ~U{1}; }\n";
1077+
const char expected[] = "unsigned int f ( ) { return ~ unsigned char ( 0 ) & ~ unsigned char { 1 } ; }";
1078+
ASSERT_EQUALS(expected, tok(code));
1079+
ASSERT_EQUALS("", errout_str());
1080+
}
1081+
10721082
void simplifyUsing8970() {
10731083
const char code[] = "using V = std::vector<int>;\n"
10741084
"struct A {\n"

0 commit comments

Comments
 (0)