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:
3
src/libs/3rdparty/cplusplus/Names.h
vendored
3
src/libs/3rdparty/cplusplus/Names.h
vendored
@@ -99,9 +99,6 @@ public:
|
|||||||
TemplateArgumentIterator firstTemplateArgument() const { return _templateArguments.begin(); }
|
TemplateArgumentIterator firstTemplateArgument() const { return _templateArguments.begin(); }
|
||||||
TemplateArgumentIterator lastTemplateArgument() const { return _templateArguments.end(); }
|
TemplateArgumentIterator lastTemplateArgument() const { return _templateArguments.end(); }
|
||||||
bool isSpecialization() const { return _isSpecialization; }
|
bool isSpecialization() const { return _isSpecialization; }
|
||||||
// this is temporary solution needed in ClassOrNamespace::nestedType
|
|
||||||
// when we try to find correct specialization for instantiation
|
|
||||||
void setIsSpecialization(bool isSpecialization) { _isSpecialization = isSpecialization; }
|
|
||||||
|
|
||||||
// Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::map)
|
// Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::map)
|
||||||
struct Compare: std::binary_function<const TemplateNameId *, const TemplateNameId *, bool> {
|
struct Compare: std::binary_function<const TemplateNameId *, const TemplateNameId *, bool> {
|
||||||
|
|||||||
@@ -1086,12 +1086,15 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
|||||||
= reference->_instantiations.constFind(templId);
|
= reference->_instantiations.constFind(templId);
|
||||||
if (citInstantiation != reference->_instantiations.constEnd())
|
if (citInstantiation != reference->_instantiations.constEnd())
|
||||||
return citInstantiation.value();
|
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;
|
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()) {
|
if (cit != specializations.end()) {
|
||||||
// we found full specialization
|
// we found full specialization
|
||||||
reference = cit->second;
|
reference = cit->second;
|
||||||
@@ -1102,8 +1105,6 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
|||||||
reference = specializationWithPointer;
|
reference = specializationWithPointer;
|
||||||
// TODO: find the best specialization(probably partial) for this instantiation
|
// 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