From 3d9f4d1ad48291c1d983e7b6deff4f5d38dca76d Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Tue, 20 May 2014 22:03:47 +0000 Subject: [PATCH] Reduce string duplication If we're so keen on saving a dynamic allocation to add the trailing space, we might as well do it in style. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209247 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 44ca495cb1..d65ba117dc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -513,35 +513,30 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result, LookupResult R(SemaRef, Name, NameLoc, Sema::LookupTagName); SemaRef.LookupParsedName(R, S, &SS); if (TagDecl *Tag = R.getAsSingle()) { - const char *TagName = 0; - const char *FixItTagName = 0; + StringRef FixItTagName; switch (Tag->getTagKind()) { case TTK_Class: - TagName = "class"; FixItTagName = "class "; break; case TTK_Enum: - TagName = "enum"; FixItTagName = "enum "; break; case TTK_Struct: - TagName = "struct"; FixItTagName = "struct "; break; case TTK_Interface: - TagName = "__interface"; FixItTagName = "__interface "; break; case TTK_Union: - TagName = "union"; FixItTagName = "union "; break; } + StringRef TagName = FixItTagName.drop_back(); SemaRef.Diag(NameLoc, diag::err_use_of_tag_name_without_tag) << Name << TagName << SemaRef.getLangOpts().CPlusPlus << FixItHint::CreateInsertion(NameLoc, FixItTagName); -- 2.40.0