Skip to content

Commit d295cc7

Browse files
committed
propagate return value instead of setting function for parenthesis
1 parent a264f34 commit d295cc7

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7789,8 +7789,6 @@ static const Function* getFunction(const Token* tok) {
77897789
return nullptr;
77907790
if (tok->function() && tok->function()->retDef)
77917791
return tok->function();
7792-
if (tok->str() == ")" && tok->link() && Token::simpleMatch(tok->link()->previous(), "_Generic ("))
7793-
return tok->link()->function();
77947792
if (const Variable* lvar = tok->variable()) { // lambda
77957793
const Function* lambda{};
77967794
if (Token::Match(lvar->nameToken()->next(), "; %varid% = [", lvar->declarationId()))
@@ -7888,7 +7886,9 @@ void SymbolDatabase::setGenericValueType(Token *par)
78887886
selected = expr;
78897887
} else {
78907888
ValueType typeVt;
7891-
parsedecl(type, &typeVt, mDefaultSignedness, mSettings);
7889+
7890+
if (!parsedecl(type, &typeVt, mDefaultSignedness, mSettings))
7891+
continue;
78927892

78937893
if (matchVt(controlVt, &typeVt)) {
78947894
selected = expr;
@@ -7900,11 +7900,18 @@ void SymbolDatabase::setGenericValueType(Token *par)
79007900
if (!selected)
79017901
return;
79027902

7903-
if (selected->valueType())
7903+
if (selected->valueType()) {
79047904
setValueType(par, *selected->valueType());
7905+
} else {
7906+
const Function *f = selected->function();
7907+
Token *parent = par->astParent();
79057908

7906-
if (selected->function())
7907-
par->function(selected->function());
7909+
if (f && f->retDef && parent && parent->str() == "(") {
7910+
ValueType returnVt;
7911+
if (parsedecl(f->retDef, &returnVt, mDefaultSignedness, mSettings))
7912+
setValueType(parent, returnVt);
7913+
}
7914+
}
79087915
}
79097916

79107917
void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *tokens)

test/testother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12715,7 +12715,7 @@ class TestOther : public TestFixture {
1271512715
" unsigned int x = 0;\n"
1271612716
" if (_Generic(x, int: ifunc, unsigned int: ufunc)(x) < 0) {}\n"
1271712717
"}\n", dinit(CheckOptions, $.cpp = false));
12718-
ASSERT_EQUALS("[test.c:6:57]: (style) Checking if unsigned expression '_Generic ( x,int:ifunc,unsigned int:ufunc)(x)' is less than zero. [unsignedLessThanZero]\n",
12718+
ASSERT_EQUALS("[test.c:6:57]: (style) Checking if unsigned expression '_Generic(x,int:ifunc,unsigned int:ufunc)(x)' is less than zero. [unsignedLessThanZero]\n",
1271912719
errout_str());
1272012720
}
1272112721

0 commit comments

Comments
 (0)