]> granicus.if.org Git - clang/commitdiff
Issue a more descriptive diagnostics when mis-declaring
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 20 Jul 2009 17:43:15 +0000 (17:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 20 Jul 2009 17:43:15 +0000 (17:43 +0000)
a destructor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76436 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
test/SemaCXX/destructor.cpp

index d65a97eb7067b661efd3fc42e410d3dc348bb2a6..d55242076a5166bfe0ccb15abde57efc620ea766 100644 (file)
@@ -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">;
 
index e2380542ae6f67c1605bc7b1291018f7d7551290..677cd819ca271bc63425de8bce01d0bdd02205fb 100644 (file)
@@ -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(),
index cefd325248a5f76b44c868494ff7ca2acd17de8b..75831ccbba2b62452d0330ed5902f10995d37a00 100644 (file)
@@ -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;
index 88e027db02ebd4ba916c6c068721c0d44ee49c66..b9b2979911ea83ac80d33939ef528d3463c508c5 100644 (file)
@@ -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;
   }
 
index f544db0b1b6e0d2a31c996dd24e2a58507663972..3cd0dba6c8989b70609c1fc8a65454c739fc9e4c 100644 (file)
@@ -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 {