Skip to content

Commit 7f1225d

Browse files
authored
refs #10663 - bail out early on some impossible matches in Library::detectContainerInternal() (danmar#8191)
1 parent 81c9ac2 commit 7f1225d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/library.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
619619
container.startPattern2 = startPattern;
620620
if (!endsWith(container.startPattern, '<'))
621621
container.startPattern2 += " !!::";
622+
container.startPatternHasStd = startsWith(container.startPattern2, "std :: ");
622623
}
623624
const char* const endPattern = node->Attribute("endPattern");
624625
if (endPattern)
@@ -1395,12 +1396,18 @@ const Library::Container* Library::detectContainerInternal(const Token* const ty
13951396
break;
13961397
}
13971398

1399+
const bool hasScope = typeStart->strAt(1) == "::";
1400+
const bool bailIfHasStd = !withoutStd && !hasScope;
1401+
13981402
for (const std::pair<const std::string, Library::Container> & c : mData->mContainers) {
13991403
const Container& container = c.second;
14001404
if (container.startPattern.empty())
14011405
continue;
14021406

1403-
const int offset = (withoutStd && startsWith(container.startPattern2, "std :: ")) ? 7 : 0;
1407+
if (bailIfHasStd && container.startPatternHasStd)
1408+
continue;
1409+
1410+
const int offset = (withoutStd && container.startPatternHasStd) ? 7 : 0;
14041411

14051412
// If endPattern is undefined, it will always match, but itEndPattern has to be defined.
14061413
if (detect != IteratorOnly && container.endPattern.empty()) {

lib/library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class CPPCHECKLIB Library {
239239
bool unstableErase{};
240240
bool unstableInsert{};
241241
bool view{};
242+
bool startPatternHasStd{};
242243

243244
Action getAction(const std::string& function) const {
244245
const auto i = utils::as_const(functions).find(function);

0 commit comments

Comments
 (0)