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
{{ message }}
Repository navigation
Commit 5587463
Browse filesBrowse the repository at this point in the historyBrowse files
Fix #15094 SymbolDatabase: Variable::isReference() is true for function pointer returning a reference (#8931)
https://trac.cppcheck.net/ticket/15094
For a function pointer returning a reference, the reference of the
return type was taken as reference of the variable:
```cpp
struct S {
std::string& (*f)(int, int);
int& (*g[2])();
};
void foo(int& (*fp)(), int&& (*fp2)());
```
`Variable::isReference()` (and `isRValueReference()` for `fp2`) was true
for all of them.
`Variable::evaluate()` now drops the reference collected before the `(`
of a function declarator, as it belongs to the return type. A `&` after
the `(` still makes the variable a reference, so `int (*&f)()`, `int
(&f)()`, `int*& r`, `int (&a)[2]` and `int& (r)` are unchanged.
The `ValueType` of the function pointer is not changed: the type of a
call `fp()` is derived from it, so its reference has to stay the one of
the return type (clearing it caused `returnTempReference` FPs).
Two places relied on the wrong flags and are adjusted:
- `checkConstVariable`: a reference to a function returning a reference
(`int& (&f)()`) was skipped only because it was wrongly flagged as
rvalue reference. References to functions are now skipped explicitly
(this also fixes the existing FP for `int (&f)()`).
- Copy/move constructor detection: `Foo(Foo&& (*f)())` was a move
constructor. With the fix it is a normal constructor, and parameters
that are references to functions (`Foo(Foo& (&f)())`) no longer make a
copy/move constructor either.
Found with #8910, where it suppressed `uninitMemberVarNoCtor` for a
struct with such a member (codelite in the PR test results). #8910
contains a workaround in CheckClass for this; with this PR merged it can
be replaced by `var.isReference()` again.
This PR was created by Claude Code (an AI coding agent) on behalf of
@autoantwort.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments