[clang] [clang][NFC] Add documentation for `CastExpr::path()`. (PR #85623)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 00:31:00 PDT 2024


https://github.com/martinboehme updated https://github.com/llvm/llvm-project/pull/85623

>From 369410916bd61671f81702c4654bd48bfc3c6c53 Mon Sep 17 00:00:00 2001
From: Martin Braenne <mboehme at google.com>
Date: Mon, 18 Mar 2024 09:51:23 +0000
Subject: [PATCH 1/2] [clang][NFC] Add documentation for `CastExpr::path()`.

This didn't have any documentation, so I had to do some experimenting in
godbolt when I used this in https://github.com/llvm/llvm-project/pull/84138,
and my reviewer later also had some
[questions](https://github.com/llvm/llvm-project/pull/84138#discussion_r1524855434)
about this, so I figured it would be worth adding documentation.
---
 clang/include/clang/AST/Expr.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 446bec4081e869..8c4db4828477d0 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,6 +3552,15 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
+  /// Path through the class hierarchy taken by a `DerivedToBase` or
+  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
+  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
+  /// the entries are ordered from derived class to base class.
+  ///
+  /// For example, given classes `Base`, `Intermediate : public Base` and
+  /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
+  /// `Base *` contains two entries: One for `Intermediate`, and one for `Base`,
+  /// in that order.
   typedef CXXBaseSpecifier **path_iterator;
   typedef const CXXBaseSpecifier *const *path_const_iterator;
   bool path_empty() const { return path_size() == 0; }

>From 571d5f4b180b2e55b03a4a43a7c0fadbee2ed25a Mon Sep 17 00:00:00 2001
From: Martin Braenne <mboehme at google.com>
Date: Tue, 19 Mar 2024 07:30:39 +0000
Subject: [PATCH 2/2] fixup! [clang][NFC] Add documentation for
 `CastExpr::path()`.

---
 clang/include/clang/AST/Expr.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 8c4db4828477d0..292cda39dc56bf 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3552,10 +3552,13 @@ class CastExpr : public Expr {
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
 
-  /// Path through the class hierarchy taken by a `DerivedToBase` or
-  /// `UncheckedDerivedToBase` cast. For each derived-to-base edge in the path,
-  /// the path contains a `CXXBaseSpecifier` for the base class of that edge;
-  /// the entries are ordered from derived class to base class.
+  /// Path through the class hierarchy taken by casts between base and derived
+  /// classes (see implementation of `CastConsistency()` for a full list of
+  /// cast kinds that have a path).
+  ///
+  /// For each derived-to-base edge in the path, the path contains a
+  /// `CXXBaseSpecifier` for the base class of that edge; the entries are
+  /// ordered from derived class to base class.
   ///
   /// For example, given classes `Base`, `Intermediate : public Base` and
   /// `Derived : public Intermediate`, the path for a cast from `Derived *` to



More information about the cfe-commits mailing list