Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
if (var && !var->isLocal() && !var->isArgument() && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) &&
!isVariableChanged(nextTok,
tok->scope()->bodyEnd,
var->valueType() ? var->valueType()->pointer : 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I recall the pointer value is different than the indirect value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how do we get the correct value here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the pointer a bitset that sets each level indirection? Or is that just const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///< 0=>not pointer, 1=>*, 2=>**, 3=>***, etc
constness and volatileness are bitsets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was confused.

var->declarationId(),
var->isGlobal(),
*mSettings)) {
Expand Down
15 changes: 15 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,21 @@ class TestAutoVariables : public TestFixture {
" int *ptr;\n"
"};");
ASSERT_EQUALS("", errout_str());

check("struct R {\n" // #11393
" void pop() { p = nullptr; };\n"
" int* p;\n"
"};\n"
"struct T {\n"
" void f();\n"
" R* r;\n"
"};\n"
"void T::f() {\n"
" int i = 0;\n"
" r->p = &i;\n"
" r->pop();\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void returnLocalVariable1() {
Expand Down
Loading