Skip to content

Commit 4abaf06

Browse files
berolinuxpaulwicking
authored andcommitted
QDoc: Adapt clang/AST/QualTypeNames.h to breaking change
For compatibility reasons, QDoc carries a custom implementation of `llvm-project.git/clang/lib/AST/QualTypeNames.cpp`. When QDoc is built against Clang libraries from LLVM 21, QDoc fails to compile with five separate errors: - no matching member function for call to 'getTemplateSpecializationType' note: candidate function not viable: requires at most 3 arguments, but 4 were provided - enumeration value 'TypeSpecWithTemplate' not handled in switch - no matching function for call to 'Create' note: candidate function not viable: no known conversion from 'const Type *' to 'const IdentifierInfo *'/'const NamespaceDecl *'/ 'const NamespaceAliasDecl *' for 3rd argument - no member named 'getQualifier' in 'clang::MemberPointerType The issues relate to several changes upstream, notably commit 14f7bd63b95d0f61a6f47119ac66398ca230559a (see [0]). This change addresses the issues by adapting QDoc's custom implementation. The required changes are wrapped in preprocessor conditionals to ensure correct behavior with LLVM versions prior to 21 as well as 21 and above. Consequentially, the change also adds 21.1 as a supported Clang version for QDoc. There is one case of output regression; the index file entry for `QMediaMetaData::asKeyValueRange<const QHash<Key, QVariant>>` from qtmultimedia.git and its signature in a list generated in qtdoc.git now partly desugars `Key` by adding template argument qualification. However, as this specific function is documented with an fn-command that overrides the declared return type using `auto`, this is considered acceptable and a matter to be addressed elsewhere. [0] - llvm/llvm-project#132401 Fixes: QTBUG-139407 Pick-to: 6.10 6.9 6.8 Change-Id: I2b1f88be27998eed6c03c9ebb068e21c6e9e3a17 Reviewed-by: Topi Reiniö <[email protected]> Reviewed-by: Paul Wicking <[email protected]>
1 parent d9a706c commit 4abaf06

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/qdoc/cmake/QDocConfiguration.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(QDOC_MINIMUM_CLANG_VERSION "17")
88

99
# List of explicitly supported Clang versions for QDoc
1010
set(QDOC_SUPPORTED_CLANG_VERSIONS
11-
"20.1" "19.1" "18.1" "17.0"
11+
"21.1" "20.1" "19.1" "18.1" "17.0"
1212
)
1313

1414
# Check for QDoc coverage dependencies

src/qdoc/qdoc/src/qdoc/clang/AST/QualTypeNames.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ QT_WARNING_DISABLE_MSVC(4267)
2525
#include "clang/AST/DeclarationName.h"
2626
#include "clang/AST/GlobalDecl.h"
2727
#include "clang/AST/Mangle.h"
28+
#include "clang/Basic/Version.h"
2829

2930
QT_WARNING_POP
3031

@@ -160,9 +161,15 @@ static inline const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
160161
// If a fully qualified arg is different from the unqualified arg,
161162
// allocate new type in the AST.
162163
if (MightHaveChanged) {
164+
#if CLANG_VERSION_MAJOR >= 21
165+
QualType QT = Ctx.getTemplateSpecializationType(
166+
TST->getTemplateName(), FQArgs, /*CanonicalArgs=*/{},
167+
TST->getCanonicalTypeInternal());
168+
#else
163169
QualType QT = Ctx.getTemplateSpecializationType(
164170
TST->getTemplateName(), FQArgs,
165171
TST->getCanonicalTypeInternal());
172+
#endif
166173
// getTemplateSpecializationType returns a fully qualified
167174
// version of the specialization itself, so no need to qualify
168175
// it.
@@ -192,9 +199,15 @@ static inline const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
192199
// allocate new type in the AST.
193200
if (MightHaveChanged) {
194201
TemplateName TN(TSTDecl->getSpecializedTemplate());
202+
#if CLANG_VERSION_MAJOR >= 21
203+
QualType QT = Ctx.getTemplateSpecializationType(
204+
TN, FQArgs, /*CanonicalArgs=*/{},
205+
TSTRecord->getCanonicalTypeInternal());
206+
#else
195207
QualType QT = Ctx.getTemplateSpecializationType(
196208
TN, FQArgs,
197209
TSTRecord->getCanonicalTypeInternal());
210+
#endif
198211
// getTemplateSpecializationType returns a fully qualified
199212
// version of the specialization itself, so no need to qualify
200213
// it.
@@ -257,7 +270,10 @@ static inline NestedNameSpecifier *getFullyQualifiedNestedNameSpecifier(
257270
Ctx, Scope->getPrefix(), WithGlobalNsPrefix);
258271
case NestedNameSpecifier::Super:
259272
case NestedNameSpecifier::TypeSpec:
260-
case NestedNameSpecifier::TypeSpecWithTemplate: {
273+
#if CLANG_VERSION_MAJOR < 21
274+
case NestedNameSpecifier::TypeSpecWithTemplate:
275+
#endif
276+
{
261277
const Type *Type = Scope->getAsType();
262278
// Find decl context.
263279
const TagDecl *TD = nullptr;
@@ -369,7 +385,10 @@ inline NestedNameSpecifier *createNestedNameSpecifier(const ASTContext &Ctx,
369385

370386
return NestedNameSpecifier::Create(
371387
Ctx, createOuterNNS(Ctx, TD, FullyQualify, WithGlobalNsPrefix),
372-
false /*No TemplateKeyword*/, TypePtr);
388+
#if CLANG_VERSION_MAJOR < 21
389+
false /*No TemplateKeyword*/,
390+
#endif
391+
TypePtr);
373392
}
374393

375394
/// Return the fully qualified type, including fully-qualified
@@ -393,9 +412,13 @@ inline QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
393412
Qualifiers Quals = QT.getQualifiers();
394413
// Fully qualify the pointee and class types.
395414
QT = getFullyQualifiedType(QT->getPointeeType(), Ctx, WithGlobalNsPrefix);
415+
#if CLANG_VERSION_MAJOR >= 21
416+
QT = Ctx.getMemberPointerType(QT, MPT->getQualifier(), MPT->getMostRecentCXXRecordDecl());
417+
#else
396418
QualType Class = getFullyQualifiedType(QualType(MPT->getClass(), 0), Ctx,
397419
WithGlobalNsPrefix);
398420
QT = Ctx.getMemberPointerType(QT, Class.getTypePtr());
421+
#endif
399422
// Add back the qualifiers.
400423
QT = Ctx.getQualifiedType(QT, Quals);
401424
return QT;

0 commit comments

Comments
 (0)