Commit a66e344b authored by Leandro Melo's avatar Leandro Melo

C++: Fix crash on invalid class name

Task-number: QTCREATORBUG-7462

Change-Id: Ic1df4b535c5a617efa707110138c76e6e7ef1e4b
Reviewed-by: default avatarRobert Löhning <robert.loehning@nokia.com>
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent ec5c280e
......@@ -1851,6 +1851,8 @@ bool Bind::visit(SimpleDeclarationAST *ast)
name = elabTypeSpec->name->name;
}
ensureValidClassName(&name, sourceLocation);
ForwardClassDeclaration *decl = control()->newForwardClassDeclaration(sourceLocation, name);
setDeclSpecifiers(decl, type);
_scope->addMember(decl);
......@@ -2882,20 +2884,7 @@ bool Bind::visit(ClassSpecifierAST *ast)
}
}
// get the unqualified class name
const QualifiedNameId *q = className->asQualifiedNameId();
const Name *unqualifiedClassName = q ? q->name() : className;
if (! unqualifiedClassName) // paranoia check
className = 0;
else if (! (unqualifiedClassName->isNameId() || unqualifiedClassName->isTemplateNameId())) {
translationUnit()->error(sourceLocation, "expected a class-name");
className = unqualifiedClassName->identifier();
if (q && className)
className = control()->qualifiedNameId(q->base(), className);
}
ensureValidClassName(&className, sourceLocation);
}
Class *klass = control()->newClass(sourceLocation, className);
......@@ -3124,6 +3113,24 @@ bool Bind::visit(ArrayDeclaratorAST *ast)
return false;
}
void Bind::ensureValidClassName(const Name **name, unsigned sourceLocation)
{
if (!*name)
return;
const QualifiedNameId *qName = (*name)->asQualifiedNameId();
if (qName)
*name = qName->name();
if (!(*name)->isNameId() && !(*name)->isTemplateNameId()) {
translationUnit()->error(sourceLocation, "expected a class-name");
*name = (*name)->identifier();
if (qName)
*name = control()->qualifiedNameId(qName->base(), *name);
}
}
int Bind::visibilityForAccessSpecifier(int tokenKind)
{
switch (tokenKind) {
......
......@@ -274,6 +274,8 @@ protected:
private:
static const int kMaxDepth;
void ensureValidClassName(const Name **name, unsigned sourceLocation);
Scope *_scope;
ExpressionTy _expression;
const Name *_name;
......
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