From 5e026f55e9e557d7370a640375407239b0f16e7e Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 20 Mar 2013 17:42:13 +0000 Subject: [PATCH] PR7256: Provide a fixit for incorrect destructor declarations Fix by Ismail Pazarbasi (ismail.pazarbasi@gmail.com), review by Dmitri Gribenko. llvm-svn: 177546 --- clang/lib/Sema/SemaExprCXX.cpp | 12 ++++++++++-- clang/test/FixIt/fixit.cpp | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 09f04b7c43e5..4b426bf62e1a 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -264,8 +264,16 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc, } else if (ObjectTypePtr) Diag(NameLoc, diag::err_ident_in_dtor_not_a_type) << &II; - else - Diag(NameLoc, diag::err_destructor_class_name); + else { + SemaDiagnosticBuilder DtorDiag = Diag(NameLoc, + diag::err_destructor_class_name); + if (S) { + const DeclContext *Ctx = static_cast(S->getEntity()); + if (const CXXRecordDecl *Class = dyn_cast_or_null(Ctx)) + DtorDiag << FixItHint::CreateReplacement(SourceRange(NameLoc), + Class->getNameAsString()); + } + } return ParsedType(); } diff --git a/clang/test/FixIt/fixit.cpp b/clang/test/FixIt/fixit.cpp index 253abd0f4e8b..fca596b715de 100644 --- a/clang/test/FixIt/fixit.cpp +++ b/clang/test/FixIt/fixit.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s // RUN: cp %s %t // RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ %t // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ %t @@ -299,3 +300,10 @@ class foo { } int i(); }; + +namespace dtor_fixit { + class foo { + ~bar() { } // expected-error {{expected the class name after '~' to name a destructor}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:6-[[@LINE-1]]:9}:"foo" + }; +}