[NFC] Prevent shadowing a variable declared in `if`
authorKen Matsui <26405363+ken-matsui@users.noreply.github.com>
Thu, 28 Apr 2022 19:45:55 +0000 (15:45 -0400)
committerHubert Tong <hubert.reinterpretcast@gmail.com>
Fri, 29 Apr 2022 02:22:27 +0000 (22:22 -0400)
Prevents confusion over which `S` is referenced in the final `else`
branch if such use is added.

Reviewed By: hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D124556

clang/lib/Basic/Diagnostic.cpp

index 3315012685d6994323cfc640ce70541c156cc590..d14134f99ee95057c8732833e245ea42fce64bc8 100644 (file)
@@ -983,13 +983,13 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
       if (const char *S = tok::getPunctuatorSpelling(Kind))
         // Quoted token spelling for punctuators.
         Out << '\'' << S << '\'';
-      else if (const char *S = tok::getKeywordSpelling(Kind))
+      else if ((S = tok::getKeywordSpelling(Kind)))
         // Unquoted token spelling for keywords.
         Out << S;
-      else if (const char *S = getTokenDescForDiagnostic(Kind))
+      else if ((S = getTokenDescForDiagnostic(Kind)))
         // Unquoted translatable token name.
         Out << S;
-      else if (const char *S = tok::getTokenName(Kind))
+      else if ((S = tok::getTokenName(Kind)))
         // Debug name, shouldn't appear in user-facing diagnostics.
         Out << '<' << S << '>';
       else