diff --git a/lib/token.h b/lib/token.h index 8377a43d4..b6f965313 100644 --- a/lib/token.h +++ b/lib/token.h @@ -651,6 +651,13 @@ public: setFlag(fIsInline, b); } + bool isRestrict() const { + return getFlag(fIsRestrict); + } + void isRestrict(bool b) { + setFlag(fIsRestrict, b); + } + bool isRemovedVoidParameter() const { return getFlag(fIsRemovedVoidParameter); } @@ -1277,6 +1284,7 @@ private: fIsSimplifedScope = (1ULL << 34), // scope added when simplifying e.g. if (int i = ...; ...) fIsRemovedVoidParameter = (1ULL << 35), // A void function parameter has been removed fIsIncompleteConstant = (1ULL << 36), + fIsRestrict = (1ULL << 37), // Is this a restrict pointer type }; Token::Type mTokType; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 11700536e..50809f86a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5498,6 +5498,8 @@ void Tokenizer::dump(std::ostream &out) const out << " isImplicitInt=\"true\""; if (tok->isComplex()) out << " isComplex=\"true\""; + if (tok->isRestrict()) + out << " isRestrict=\"true\""; if (tok->link()) out << " link=\"" << tok->link() << '\"'; if (tok->varId() > 0) @@ -11249,11 +11251,14 @@ void Tokenizer::simplifyKeyword() if (keywords.find(tok->str()) != keywords.end()) { // Don't remove struct members if (!Token::simpleMatch(tok->previous(), ".")) { - if (tok->str().find("inline") != std::string::npos) { - Token *temp = tok->next(); - while (temp != nullptr && Token::Match(temp, "%name%")) { - temp->isInline(true); - temp = temp->next(); + const bool isinline = (tok->str().find("inline") != std::string::npos); + const bool isrestrict = (tok->str().find("restrict") != std::string::npos); + if (isinline || isrestrict) { + for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) { + if (isinline) + temp->isInline(true); + if (isrestrict) + temp->isRestrict(true); } } tok->deleteThis(); // Simplify.. @@ -11271,8 +11276,12 @@ void Tokenizer::simplifyKeyword() tok->deleteNext(); if (c99) { - while (tok->str() == "restrict") + if (tok->str() == "restrict") { + for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) { + temp->isRestrict(true); + } tok->deleteThis(); + } if (mSettings->standards.c >= Standards::C11) { while (tok->str() == "_Atomic")