Commit 603da061 authored by Milian Wolff's avatar Milian Wolff

Check type validity after call to TypeUtils::realType.

It internally also does not assume that, given a valid type, it
will return a valid type. This hints at issues we have with parsing
some code and creating reference types or type aliases pointing at
invalid other types.

At least now we hopefully don't crash anymore.

BUG: 318972
parent a478dd8b
......@@ -458,21 +458,8 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression)
}
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 ( 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 );
openedType = true;
}
......@@ -492,6 +479,33 @@ void TypeBuilder::createIntegralTypeForExpression(ExpressionAST* expression)
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) {
if(m_onlyComputeSimplified) {
return;
......
......@@ -162,6 +162,7 @@ private:
KDevelop::FunctionType* openFunction(DeclaratorAST *node);
void createIntegralTypeForExpression(ExpressionAST *expression);
AbstractType::Ptr prepareTypeForExpression(AbstractType::Ptr type, quint64 modifiers);
int m_currentEnumeratorValue;
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