C++: fix constructor definition parsing.

When a constructor is defined with a single, unnamed argument of a custom type without
extra type specifiers (const...), then the constructor was not identified as such.
There was an heuristic in case the constructor was in the class definition, but not if the
the constructor was defined later.

Examples:

class Arg;
class Other;

class Foo {
  Foo(Arg /*arg*/);               // working
  Foo(const Arg /*arg*/);         // working
  Foo(int /*arg*/);               // working
  Foo(Other /*arg*/)         {}   // working
};

Foo::Foo(Arg /*arg*/)        {}   // used not to work, fixed
Foo::Foo(Arg arg){}               // working
Foo::Foo(const Arg /*arg*/)  {}   // working
Foo::Foo(int arg)            {}   // working

Change-Id: I741e4ba62672ddc99a837fdcdc27996fba5ae6c7
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Francois Ferrand
2013-01-04 10:55:44 +01:00
committed by hjk
parent 110f0d8a9e
commit 5e8c3f4be7
2 changed files with 164 additions and 5 deletions

View File

@@ -3904,12 +3904,17 @@ bool Parser::parseSimpleDeclaration(DeclarationAST *&node, ClassSpecifierAST *de
startOfNamedTypeSpecifier = cursor();
if (parseName(named_type_specifier)) {
if (LA() == T_LPAREN && identifier(named_type_specifier) == className(declaringClass)) {
// looks like a constructor declaration
rewind(startOfNamedTypeSpecifier);
break;
}
const Identifier *classIdentifier = className(declaringClass);
if (QualifiedNameAST *qn = named_type_specifier->asQualifiedName())
if (NestedNameSpecifierListAST *namesList = qn->nested_name_specifier_list)
if (NestedNameSpecifierAST *lastName = namesList->lastValue())
classIdentifier = identifier(lastName->class_or_namespace_name);
if (LA() == T_LPAREN && identifier(named_type_specifier) == classIdentifier) {
// looks like a constructor declaration
rewind(startOfNamedTypeSpecifier);
break;
}
NamedTypeSpecifierAST *spec = new (_pool) NamedTypeSpecifierAST;
spec->name = named_type_specifier;