diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-20 17:43:15 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-20 17:43:15 +0000 |
commit | d33c868d386ef47c2942e2dbff0d9955a8591fa9 (patch) | |
tree | 43c9c09bf73be1c4594e0bec8b254c21e3f8eb3f | |
parent | 89021b0c71c53c88927b588431859a041bec2802 (diff) |
Issue a more descriptive diagnostics when mis-declaring
a destructor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76436 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 3 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 6 | ||||
-rw-r--r-- | test/SemaCXX/destructor.cpp | 4 |
5 files changed, 12 insertions, 7 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index d65a97eb70..d55242076a 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -138,6 +138,8 @@ def err_missing_param : Error<"expected parameter declarator">; def err_unexpected_typedef_ident : Error< "unexpected type name %0: expected identifier">; def err_expected_class_name : Error<"expected class name">; +def err_destructor_class_name : Error< + "destructor name must be same as the class name">; def err_unspecified_vla_size_with_static : Error< "'static' may not be used with an unspecified variable length array size">; diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index e2380542ae..677cd819ca 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1129,7 +1129,8 @@ private: //===--------------------------------------------------------------------===// // C++ 9: classes [class] and C structs/unions. TypeResult ParseClassName(SourceLocation &EndLocation, - const CXXScopeSpec *SS = 0); + const CXXScopeSpec *SS = 0, + bool DestrExpected = false); void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index cefd325248..75831ccbba 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2194,13 +2194,13 @@ void Parser::ParseDirectDeclarator(Declarator &D) { SourceLocation NameLoc = Tok.getLocation(); SourceLocation EndLoc; CXXScopeSpec *SS = afterCXXScope? &D.getCXXScopeSpec() : 0; - TypeResult Type = ParseClassName(EndLoc, SS); + TypeResult Type = ParseClassName(EndLoc, SS, true); if (Type.isInvalid()) D.SetIdentifier(0, TildeLoc); else D.setDestructor(Type.get(), TildeLoc, NameLoc); } else { - Diag(Tok, diag::err_expected_class_name); + Diag(Tok, diag::err_destructor_class_name); D.SetIdentifier(0, TildeLoc); } goto PastIdentifier; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 88e027db02..b9b2979911 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -427,7 +427,8 @@ void Parser::ParseDecltypeSpecifier(DeclSpec &DS) { /// simple-template-id /// Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, - const CXXScopeSpec *SS) { + const CXXScopeSpec *SS, + bool DestrExpected) { // Check whether we have a template-id that names a type. if (Tok.is(tok::annot_template_id)) { TemplateIdAnnotation *TemplateId @@ -457,7 +458,8 @@ Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, TypeTy *Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), CurScope, SS); if (!Type) { - Diag(Tok, diag::err_expected_class_name); + Diag(Tok, DestrExpected ? diag::err_destructor_class_name + : diag::err_expected_class_name); return true; } diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index f544db0b1b..3cd0dba6c8 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -40,8 +40,8 @@ struct F { ~F(); // expected-error {{destructor cannot be redeclared}} }; -~; // expected-error {{expected class name}} -~undef(); // expected-error {{expected class name}} +~; // expected-error {{destructor name must be same as the class name}} +~undef(); // expected-error {{destructor name must be same as the class name}} ~F(){} // expected-error {{destructor must be a non-static member function}} struct G { |