[cfe-commits] r76436 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp test/SemaCXX/destructor.cpp
Douglas Gregor
dgregor at apple.com
Mon Jul 20 15:20:18 PDT 2009
On Jul 20, 2009, at 10:43 AM, Fariborz Jahanian wrote:
> Author: fjahanian
> Date: Mon Jul 20 12:43:15 2009
> New Revision: 76436
>
> URL: http://llvm.org/viewvc/llvm-project?rev=76436&view=rev
> Log:
> Issue a more descriptive diagnostics when mis-declaring
> a destructor.
I don't think that the diagnostic "destructor name must be same as the
class name" is much of an improvement. Perhaps something like,
"expected the class name after '~' to name a destructor"?
It fits better for (admittedly stupid) cases like, e.g., "~operator+
(int, int)".
(another comment further down)
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> cfe/trunk/include/clang/Parse/Parser.h
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> cfe/trunk/test/SemaCXX/destructor.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=76436&r1=76435&r2=76436&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Jul 20
> 12:43:15 2009
> @@ -138,6 +138,8 @@
> 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">;
>
>
> Modified: cfe/trunk/include/clang/Parse/Parser.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=76436&r1=76435&r2=76436&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Parse/Parser.h (original)
> +++ cfe/trunk/include/clang/Parse/Parser.h Mon Jul 20 12:43:15 2009
> @@ -1129,7 +1129,8 @@
> //
> =
> =
> =--------------------------------------------------------------------
> ===//
> // 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(),
>
> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=76436&r1=76435&r2=76436&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jul 20 12:43:15 2009
> @@ -2194,13 +2194,13 @@
> 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;
In addition to these parser-level checks, we're missing the semantic
checks to diagnose this error:
struct X { };
struct Y {
~X() { }
};
- Doug
More information about the cfe-commits
mailing list