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

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 7 20:05:00 PST 2024


================
@@ -813,6 +813,18 @@ TEST(SourceCodeTests, isKeywords) {
   EXPECT_FALSE(isKeyword("override", LangOpts));
 }
 
+TEST(SourceCodeTests, isSpelledInSource) {
+  Annotations Test("");
+  ParsedAST AST = TestTU::withCode(Test.code()).build();
+  const SourceManager &SM = AST.getSourceManager();
+
+  EXPECT_TRUE(
+      isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM));
+  EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM));
----------------
HighCommander4 wrote:

I think it's worth adding a couple of comments here.

First:

```c++
// Check that isSpelledInSource() handles various invalid source locations gracefully.
```

But also, a slightly more subtle point:

```c++
// Returning true for SourceLocation() is a behavior that falls out of the current
// implementation, which has an early exit for isFileID().
// FIXME: Should it return false on SourceLocation()? Does it matter?
```

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


More information about the cfe-commits mailing list