Skip to content

[ExtractAPI] Include virtual keyword for methods #145412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

snprajwal
Copy link
Contributor

This information was being left out of the symbol graph.

rdar://131780883

This information was being left out of the symbol graph.

rdar://131780883
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-clang

Author: Prajwal Nadig (snprajwal)

Changes

This information was being left out of the symbol graph.

rdar://131780883


Full diff: https://github.com/llvm/llvm-project/pull/145412.diff

2 Files Affected:

  • (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+3)
  • (modified) clang/test/ExtractAPI/methods.cpp (+9-1)
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index d7eebcbc3c2f9..348e7588690a2 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -883,6 +883,9 @@ DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForCXXMethod(
   if (Method->isVolatile())
     Fragments.append("volatile", DeclarationFragments::FragmentKind::Keyword)
         .appendSpace();
+  if (Method->isVirtual())
+    Fragments.append("virtual", DeclarationFragments::FragmentKind::Keyword)
+        .appendSpace();
 
   // Build return type
   DeclarationFragments After;
diff --git a/clang/test/ExtractAPI/methods.cpp b/clang/test/ExtractAPI/methods.cpp
index 67f04b4d33db8..180c2f92b2772 100644
--- a/clang/test/ExtractAPI/methods.cpp
+++ b/clang/test/ExtractAPI/methods.cpp
@@ -45,11 +45,19 @@ class Foo {
   // GETCOUNT-NEXT: ]
 
   // RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix SETL
-  void setLength(int length) noexcept;
+  virtual void setLength(int length) noexcept;
   // SETL: "!testRelLabel": "memberOf $ c:@S@Foo@F@setLength#I# $ c:@S@Foo"
   // SETL-LABEL: "!testLabel": "c:@S@Foo@F@setLength#I#"
   // SETL:      "declarationFragments": [
   // SETL-NEXT:   {
+  // SETL-NEXT:     "kind": "keyword",
+  // SETL-NEXT:     "spelling": "virtual"
+  // SETL-NEXT:   },
+  // SETL-NEXT:   {
+  // SETL-NEXT:     "kind": "text",
+  // SETL-NEXT:     "spelling": " "
+  // SETL-NEXT:   },
+  // SETL-NEXT:   {
   // SETL-NEXT:     "kind": "typeIdentifier",
   // SETL-NEXT:     "preciseIdentifier": "c:v",
   // SETL-NEXT:     "spelling": "void"

Copy link
Contributor

@QuietMisdreavus QuietMisdreavus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!

@QuietMisdreavus QuietMisdreavus merged commit 23b66a6 into llvm:main Jun 23, 2025
9 checks passed
@snprajwal snprajwal deleted the extractapi/virtual-method branch June 23, 2025 23:25
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
This information was being left out of the symbol graph.

rdar://131780883
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
This information was being left out of the symbol graph.

rdar://131780883
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants