[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 03:32:05 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Vipul Cariappa (Vipul-Cariappa)

<details>
<summary>Changes</summary>

Return the first `Decl` when using `TranslationUnitDecl::getCanonicalDecl`

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


1 Files Affected:

- (modified) clang/include/clang/AST/Decl.h (+4) 


``````````diff
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 0600ecc4d14a18..7ff35d73df5997 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -133,6 +133,10 @@ class TranslationUnitDecl : public Decl,
   static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
     return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
   }
+
+  /// Retrieves the canonical declaration of this translation unit.
+  TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); }
+  const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); }
 };
 
 /// Represents a `#pragma comment` line. Always a child of

``````````

</details>


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


More information about the cfe-commits mailing list