Skip to content

Commit 4bdbbc2

Browse files
committed
Add getPointerLikeOrArrayElementType()
1 parent f0350e1 commit 4bdbbc2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/include/clang/AST/Type.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
28822882
/// - DecayedType
28832883
QualType getPointeeType() const;
28842884

2885+
/// Return getElementType() if this is an array type, and getPointeeType()
2886+
/// otherwise.
2887+
QualType getPointerLikeOrArrayElementType() const;
2888+
28852889
/// Return the specified type with any "sugar" removed from the type,
28862890
/// removing any typedefs, typeofs, etc., as well as any qualifiers.
28872891
const Type *getUnqualifiedDesugaredType() const;

clang/lib/AST/Type.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ QualType Type::getPointeeType() const {
751751
return {};
752752
}
753753

754+
QualType Type::getPointerLikeOrArrayElementType() const {
755+
if (const auto *A = getAs<ArrayType>())
756+
return A->getElementType();
757+
return getPointeeType();
758+
}
759+
754760
const RecordType *Type::getAsStructureType() const {
755761
// If this is directly a structure type, return it.
756762
if (const auto *RT = dyn_cast<RecordType>(this)) {

0 commit comments

Comments
 (0)