forked from qt-creator/qt-creator
C++: Remove concurrent access to TemplateNameId
The modification of the TemplateNameId changed "global state" because the TemplateNameId is potentially accessed by multiple threads doing lookup (access to same document and thus same symbol names). Depending on the thread scheduling and access to ClassOrNamespace::_specializations, the changed TemplateNameId "suddenly" led to inconsistent results of TemplateNameId::Compare and thus broke the std::map assertions. Get rid of the const_cast, the setter and simply construct a temporary TemplateNameId with isSpecializaton = true. Task-number: QTCREATORBUG-14911 Change-Id: Ie381d132cc0d06af351ace4257773637d1ebee4e Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1086,12 +1086,15 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
||||
= reference->_instantiations.constFind(templId);
|
||||
if (citInstantiation != reference->_instantiations.constEnd())
|
||||
return citInstantiation.value();
|
||||
TemplateNameId *nonConstTemplId = const_cast<TemplateNameId *>(templId);
|
||||
// make this instantiation looks like specialization which help to find
|
||||
// full specialization for this instantiation
|
||||
nonConstTemplId->setIsSpecialization(true);
|
||||
|
||||
const TemplateNameIdTable &specializations = reference->_specializations;
|
||||
TemplateNameIdTable::const_iterator cit = specializations.find(templId);
|
||||
const TemplateNameId templIdAsSpecialization(templId->identifier(),
|
||||
/*isSpecializaton=*/ true,
|
||||
templId->firstTemplateArgument(),
|
||||
templId->lastTemplateArgument());
|
||||
TemplateNameIdTable::const_iterator cit
|
||||
= specializations.find(&templIdAsSpecialization);
|
||||
|
||||
if (cit != specializations.end()) {
|
||||
// we found full specialization
|
||||
reference = cit->second;
|
||||
@@ -1102,8 +1105,6 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
||||
reference = specializationWithPointer;
|
||||
// TODO: find the best specialization(probably partial) for this instantiation
|
||||
}
|
||||
// let's instantiation be instantiation
|
||||
nonConstTemplId->setIsSpecialization(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user