Opened 4 weeks ago
#15094 new enhancement
SymbolDatabase: Variable::isReference() is true for function pointer returning a reference
| Reported by: | autoantwort | Owned by: | noone |
|---|---|---|---|
| Priority: | Normal | Milestone: | 2.23 |
| Component: | Other | Version: | |
| Keywords: | SymbolDatabase | Cc: |
Description
struct S {
std::string& (*f)(int, int);
int& (*g[2])();
};
void foo(int& (*fp)(), int&& (*fp2)());
Variable::isReference() (and isRValueReference() for fp2) is true for f, g, fp and fp2, and their
ValueType has reference == Reference::LValue/RValue. The reference belongs to the return type of the function
pointer, the variables themselves are pointers (or an array of pointers). Real references to function pointers like
int (*&f)() are correct.
Variable::evaluate() sets the reference flag for every & between the type start and end token, which includes the
return type of a function pointer before the (. parsedecl() keeps the reference of the return type as well.
Found with PR #8910 (https://github.com/cppcheck-opensource/cppcheck/pull/8910), where it suppressed
uninitMemberVarNoCtor for a struct with such a member (codelite in the PR test results). #8910 contains a workaround
in CheckClass that can be removed after this is fixed.