Skip to content

Commit a84a979

Browse files
Merge pull request #674 from andreasfertig/clang19Compile
Clang 19 compile
2 parents a77baff + 1c512fa commit a84a979

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

CodeGenerator.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,13 +1729,26 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
17291729
if(tt->hasDefaultArgument() and not tt->defaultArgumentWasInherited()) {
17301730
const auto& defaultArg = tt->getDefaultArgument();
17311731

1732-
if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(defaultArg.getTypePtrOrNull())) {
1732+
if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(defaultArg
1733+
.
1734+
#if IS_CLANG_NEWER_THAN(18)
1735+
getArgument()
1736+
.getAsType()
1737+
#else
1738+
getTypePtrOrNull()
1739+
#endif
1740+
)) {
17331741
mOutputFormatHelper.Append(hlpAssing);
17341742

17351743
InsertArg(decltypeType->getUnderlyingExpr());
17361744

17371745
} else {
1738-
mOutputFormatHelper.Append(hlpAssing, GetName(defaultArg));
1746+
mOutputFormatHelper.Append(hlpAssing);
1747+
InsertTemplateArg(defaultArg
1748+
#if IS_CLANG_NEWER_THAN(18)
1749+
.getArgument()
1750+
#endif
1751+
);
17391752
}
17401753
}
17411754

@@ -1752,7 +1765,11 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
17521765

17531766
if(nonTmplParam->hasDefaultArgument()) {
17541767
mOutputFormatHelper.Append(hlpAssing);
1768+
#if IS_CLANG_NEWER_THAN(18)
1769+
InsertTemplateArg(nonTmplParam->getDefaultArgument().getArgument());
1770+
#else
17551771
InsertArg(nonTmplParam->getDefaultArgument());
1772+
#endif
17561773
}
17571774
} else {
17581775
mOutputFormatHelper.Append(typeName, EllipsisSpace(nonTmplParam->isParameterPack()));
@@ -3008,9 +3025,29 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
30083025
mOutputFormatHelper.Append(kwUsingSpace, GetName(*stmt), hlpAssing);
30093026

30103027
if(auto* templateSpecializationType = underlyingType->getAs<TemplateSpecializationType>()) {
3028+
#if IS_CLANG_NEWER_THAN(18)
3029+
const bool carriesNamespace{[&] {
3030+
if(const auto tn = templateSpecializationType->getTemplateName();
3031+
(TemplateName::QualifiedTemplate == tn.getKind()) or (TemplateName::DependentTemplate == tn.getKind())) {
3032+
const auto* qtn = tn.getAsQualifiedTemplateName();
3033+
3034+
return qtn->getQualifier() != nullptr;
3035+
}
3036+
3037+
return false;
3038+
}()};
3039+
3040+
if(const auto* elaboratedType = underlyingType->getAs<ElaboratedType>()) {
3041+
if(templateSpecializationType->isSugared() and not carriesNamespace) {
3042+
// do this only if the templateSpecializationType does not carry a nestedns
3043+
InsertNamespace(elaboratedType->getQualifier());
3044+
}
3045+
}
3046+
#else
30113047
if(const auto* elaboratedType = underlyingType->getAs<ElaboratedType>()) {
30123048
InsertNamespace(elaboratedType->getQualifier());
30133049
}
3050+
#endif
30143051

30153052
StringStream stream{};
30163053
stream.Print(*templateSpecializationType);
@@ -3686,7 +3723,10 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
36863723

36873724
// attributes start with a space, skip it as it is not required for the first attribute
36883725
std::string_view start{stream.str()};
3726+
#if IS_CLANG_NEWER_THAN(18)
3727+
#else
36893728
start.remove_prefix(1);
3729+
#endif
36903730

36913731
mOutputFormatHelper.Append(start, " "sv);
36923732
}
@@ -4426,12 +4466,20 @@ void CodeGenerator::InsertSuffix(const QualType& type)
44264466

44274467
void CodeGenerator::InsertTemplateArgs(const ClassTemplateSpecializationDecl& clsTemplateSpe)
44284468
{
4469+
#if IS_CLANG_NEWER_THAN(18)
4470+
if(const auto* ar = clsTemplateSpe.getTemplateArgsAsWritten()) {
4471+
InsertTemplateArgs(ar->arguments());
4472+
} else {
4473+
InsertTemplateArgs(clsTemplateSpe.getTemplateArgs());
4474+
}
4475+
#else
44294476
if(const TypeSourceInfo* typeAsWritten = clsTemplateSpe.getTypeAsWritten()) {
44304477
const TemplateSpecializationType* tmplSpecType = cast<TemplateSpecializationType>(typeAsWritten->getType());
44314478
InsertTemplateArgs(*tmplSpecType);
44324479
} else {
44334480
InsertTemplateArgs(clsTemplateSpe.getTemplateArgs());
44344481
}
4482+
#endif
44354483
}
44364484
//-----------------------------------------------------------------------------
44374485

Insights.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class FindIncludes : public PPCallbacks
130130
StringRef /*SearchPath*/,
131131
StringRef /*RelativePath*/,
132132
const Module* /*Imported*/,
133+
#if IS_CLANG_NEWER_THAN(18)
134+
bool /*ModuleImported*/,
135+
#endif
133136
SrcMgr::CharacteristicKind /*FileType*/) override
134137
{
135138
auto expansionLoc = mSm.getExpansionLoc(hashLoc);

InsightsHelpers.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,8 @@ BuildNamespace(std::string& fullNamespace, const NestedNameSpecifier* stmt, cons
180180
case NestedNameSpecifier::NamespaceAlias: fullNamespace.append(stmt->getAsNamespaceAlias()->getName()); break;
181181

182182
case NestedNameSpecifier::TypeSpecWithTemplate:
183-
if(
184-
#if IS_CLANG_NEWER_THAN(17)
185-
ElaboratedTypeKeyword::Typename
186-
#else
187-
ElaboratedTypeKeyword::ETK_Typename
188-
#endif
189-
== stmt->getAsType()->getAs<DependentTemplateSpecializationType>()->getKeyword()) {
190-
fullNamespace.append(kwTemplateSpace);
183+
if(auto* dependentSpecType = stmt->getAsType()->getAs<DependentTemplateSpecializationType>()) {
184+
fullNamespace.append(GetElaboratedTypeKeyword(dependentSpecType->getKeyword()));
191185
}
192186

193187
[[fallthrough]];

0 commit comments

Comments
 (0)