Library: Allow that type of function return is specified. Fixes #7668.
This commit is contained in:
parent
f25d205999
commit
c8f831b70d
|
@ -10,7 +10,7 @@
|
|||
<pure/>
|
||||
<noreturn>false</noreturn>
|
||||
<leak-ignore/>
|
||||
<returnValue>arg1>0?arg1:-arg1</returnValue>
|
||||
<returnValue type="int">arg1>0?arg1:-arg1</returnValue>
|
||||
<arg nr="1">
|
||||
<not-uninit/>
|
||||
<not-bool/>
|
||||
|
|
|
@ -545,9 +545,12 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
|||
leakignore.insert(name);
|
||||
else if (functionnodename == "use-retval")
|
||||
_useretval.insert(name);
|
||||
else if (functionnodename == "returnValue" && functionnode->GetText())
|
||||
else if (functionnodename == "returnValue" && functionnode->GetText()) {
|
||||
_returnValue[name] = functionnode->GetText();
|
||||
else if (functionnodename == "arg") {
|
||||
const char *type = functionnode->Attribute("type");
|
||||
if (type)
|
||||
_returnValueType[name] = type;
|
||||
} else if (functionnodename == "arg") {
|
||||
const char* argNrString = functionnode->Attribute("nr");
|
||||
if (!argNrString)
|
||||
return Error(MISSING_ATTRIBUTE, "nr");
|
||||
|
@ -995,6 +998,14 @@ std::string Library::returnValue(const Token *ftok) const
|
|||
return it != _returnValue.end() ? it->second : std::string();
|
||||
}
|
||||
|
||||
std::string Library::returnValueType(const Token *ftok) const
|
||||
{
|
||||
if (isNotLibraryFunction(ftok))
|
||||
return std::string();
|
||||
std::map<std::string, std::string>::const_iterator it = _returnValueType.find(getFunctionName(ftok));
|
||||
return it != _returnValueType.end() ? it->second : std::string();
|
||||
}
|
||||
|
||||
bool Library::isnoreturn(const Token *ftok) const
|
||||
{
|
||||
if (ftok->function() && ftok->function()->isAttributeNoreturn())
|
||||
|
|
|
@ -166,6 +166,7 @@ public:
|
|||
bool isUseRetVal(const Token* ftok) const;
|
||||
|
||||
std::string returnValue(const Token *ftok) const;
|
||||
std::string returnValueType(const Token *ftok) const;
|
||||
|
||||
bool isnoreturn(const Token *ftok) const;
|
||||
bool isnotnoreturn(const Token *ftok) const;
|
||||
|
@ -481,6 +482,7 @@ private:
|
|||
std::set<std::string> _functions;
|
||||
std::map<std::string, bool> _noreturn; // is function noreturn?
|
||||
std::map<std::string, std::string> _returnValue;
|
||||
std::map<std::string, std::string> _returnValueType;
|
||||
std::set<std::string> _ignorefunction; // ignore functions/macros from a library (gtk, qt etc)
|
||||
std::map<std::string, bool> _reporterrors;
|
||||
std::map<std::string, bool> _processAfterCode;
|
||||
|
|
|
@ -4602,6 +4602,12 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
|
|||
::setValueType(tok, valuetype, cpp, defsign, settings);
|
||||
}
|
||||
|
||||
// library function
|
||||
else if (tok->previous() && settings->library.returnValueType(tok->previous()) == "int") {
|
||||
ValueType valuetype(ValueType::Sign::SIGNED, ValueType::Type::INT, 0U);
|
||||
::setValueType(tok, valuetype, cpp, defsign, settings);
|
||||
}
|
||||
|
||||
else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
|
||||
// TODO: use specified size_t type
|
||||
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U);
|
||||
|
|
Loading…
Reference in New Issue