[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 1 00:20:51 PST 2024


================
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
   if (Loc.isFileID())
     return true;
   auto Spelling = SM.getDecomposedSpellingLoc(Loc);
-  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  bool InvalidSLocEntry = false;
+  const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
+  if (InvalidSLocEntry) {
+    return false;
+  }
----------------
zyn0217 wrote:

```suggestion
  if (InvalidSLocEntry)
    return false;
```
We don't usually add braces to one-line-if statements.

See https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.

https://github.com/llvm/llvm-project/pull/76668


More information about the cfe-commits mailing list