Commit a2952a03 authored by Milian Wolff's avatar Milian Wolff

Backport crash fixes for crash in Cpp TypeBuilder.

This is a backport of the two following commits in branch master:
ce1dde3b
603da061

CCBUG: 318972
parent 36d40ae8
...@@ -458,21 +458,8 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression) ...@@ -458,21 +458,8 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression)
} }
if ( !delay && res.isValid() && res.isInstance ) { if ( !delay && res.isValid() && res.isInstance ) {
AbstractType::Ptr type = res.type.abstractType(); const AbstractType::Ptr& type = prepareTypeForExpression(res.type.abstractType(), integral->modifiers());
if (type) { if (type) {
if ( m_lastTypeWasAuto ) {
// remove references or aliases
type = TypeUtils::realType( type, topContext() );
// Turn "5" into "int"
type = TypeUtils::removeConstants( type, topContext() );
// ensure proper const modifier is set
type->setModifiers( integral->modifiers() );
if (ReferenceType::Ptr ref = lastType().cast<ReferenceType>()) {
ref->setBaseType( type );
type = ref.cast<AbstractType>();
}
}
openType( type ); openType( type );
openedType = true; openedType = true;
} }
...@@ -492,6 +479,33 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression) ...@@ -492,6 +479,33 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression)
closeType(); closeType();
} }
AbstractType::Ptr TypeBuilder::prepareTypeForExpression(AbstractType::Ptr type, quint64 modifiers)
{
if (!m_lastTypeWasAuto) {
return type;
}
// remove references or aliases
type = TypeUtils::realType( type, topContext() );
// Turn "5" into "int"
type = TypeUtils::removeConstants( type, topContext() );
if (!type) {
// NOTE: the type might not be valid anymore, see https://bugs.kde.org/show_bug.cgi?id=318972
return type;
}
// ensure proper const modifier is set
type->setModifiers( modifiers );
if (ReferenceType::Ptr ref = lastType().cast<ReferenceType>()) {
ref->setBaseType( type );
type = ref.cast<AbstractType>();
}
return type;
}
void TypeBuilder::createTypeForInitializer(InitializerAST *node) { void TypeBuilder::createTypeForInitializer(InitializerAST *node) {
if(m_onlyComputeSimplified) { if(m_onlyComputeSimplified) {
return; return;
...@@ -589,6 +603,7 @@ bool TypeBuilder::openTypeFromName(NameAST* name, uint modifiers, bool needClass ...@@ -589,6 +603,7 @@ bool TypeBuilder::openTypeFromName(NameAST* name, uint modifiers, bool needClass
openedType = true; openedType = true;
IndexedTypeIdentifier typeId(id); IndexedTypeIdentifier typeId(id);
typeId.setIsConstant(modifiers & AbstractType::ConstModifier); typeId.setIsConstant(modifiers & AbstractType::ConstModifier);
typeId.setIsVolatile(modifiers & AbstractType::VolatileModifier);
openDelayedType(typeId, name, templateDeclarationDepth() ? DelayedType::Delayed : DelayedType::Unresolved ); openDelayedType(typeId, name, templateDeclarationDepth() ? DelayedType::Delayed : DelayedType::Unresolved );
......
...@@ -162,6 +162,7 @@ private: ...@@ -162,6 +162,7 @@ private:
KDevelop::FunctionType* openFunction(DeclaratorAST *node); KDevelop::FunctionType* openFunction(DeclaratorAST *node);
void createIntegralTypeForExpression(ExpressionAST *expression); void createIntegralTypeForExpression(ExpressionAST *expression);
AbstractType::Ptr prepareTypeForExpression(AbstractType::Ptr type, quint64 modifiers);
int m_currentEnumeratorValue; int m_currentEnumeratorValue;
bool m_lastTypeWasInstance; bool m_lastTypeWasInstance;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment