From f4d17c4f22184e5ac5595e38f86eb86900535502 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 27 Mar 2009 04:38:56 +0000 Subject: Improve recovery when a constructor fails to type-check. Test case from Anders llvm-svn: 67818 --- clang/lib/Sema/SemaDeclCXX.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'clang/lib/Sema/SemaDeclCXX.cpp') diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index bb306e4a0f1..f22686020e4 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1289,20 +1289,22 @@ bool Sema::CheckConstructorDeclarator(Declarator &D, QualType &R, /// well-formedness, issuing any diagnostics required. Returns true if /// the constructor declarator is invalid. bool Sema::CheckConstructor(CXXConstructorDecl *Constructor) { - if (Constructor->isInvalidDecl()) + CXXRecordDecl *ClassDecl + = dyn_cast(Constructor->getDeclContext()); + if (!ClassDecl) return true; - CXXRecordDecl *ClassDecl = cast(Constructor->getDeclContext()); - bool Invalid = false; + bool Invalid = Constructor->isInvalidDecl(); // C++ [class.copy]p3: // A declaration of a constructor for a class X is ill-formed if // its first parameter is of type (optionally cv-qualified) X and // either there are no other parameters or else all other // parameters have default arguments. - if ((Constructor->getNumParams() == 1) || - (Constructor->getNumParams() > 1 && - Constructor->getParamDecl(1)->getDefaultArg() != 0)) { + if (!Constructor->isInvalidDecl() && + ((Constructor->getNumParams() == 1) || + (Constructor->getNumParams() > 1 && + Constructor->getParamDecl(1)->getDefaultArg() != 0))) { QualType ParamType = Constructor->getParamDecl(0)->getType(); QualType ClassTy = Context.getTagDeclType(ClassDecl); if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) { -- cgit v1.2.3