Repository navigation
Fix #15094 SymbolDatabase: Variable::isReference() is true for function pointer returning a reference #8931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2595,6 +2595,10 @@ void Variable::evaluate(const Settings& settings) | |
| } else if (tok->str() == "&&") { // Before simplification, && isn't split up | ||
| setFlag(fIsRValueRef, true); | ||
| setFlag(fIsReference, true); // Set also fIsReference | ||
| } else if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") (")) { | ||
| // a reference before the parentheses belongs to the return type of a function pointer: int& (*f)() | ||
| setFlag(fIsRValueRef, false); | ||
| setFlag(fIsReference, false); | ||
| } | ||
|
|
||
| if (tok->str() == "<" && tok->link()) | ||
|
|
@@ -7578,6 +7582,8 @@ static const Token* parsedecl(const Token* type, | |
| if (par) | ||
| break; | ||
| par = true; | ||
| // a reference before the parentheses belongs to the return type of the function pointer | ||
| valuetype->reference = Reference::None; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reset only runs for |
||
| } | ||
| if (Token::simpleMatch(type, "decltype (") && type->next()->valueType()) { | ||
| const ValueType *vt2 = type->next()->valueType(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reset is only reached for
( *. For a pointer to member function returning a reference, e.g.int& (S::*pm)();, the loop breaks atif (!Token::simpleMatch(type, "( *")) break;first, sovaluetype->referenceprobably staysLValue. MeanwhileVariable::evaluate()resets on any(, soisReference()would be false. That makesVariableandValueTypedisagree. Consider resetting the reference before the( *check (whenevertypeis(and we're stopping on a declarator), or handling( %name% :: *as well. A test forint& (S::*pm)()would cover this.