@@ -1729,13 +1729,26 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
1729
1729
if (tt->hasDefaultArgument () and not tt->defaultArgumentWasInherited ()) {
1730
1730
const auto & defaultArg = tt->getDefaultArgument ();
1731
1731
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
+ )) {
1733
1741
mOutputFormatHelper .Append (hlpAssing);
1734
1742
1735
1743
InsertArg (decltypeType->getUnderlyingExpr ());
1736
1744
1737
1745
} 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
+ );
1739
1752
}
1740
1753
}
1741
1754
@@ -1752,7 +1765,11 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
1752
1765
1753
1766
if (nonTmplParam->hasDefaultArgument ()) {
1754
1767
mOutputFormatHelper .Append (hlpAssing);
1768
+ #if IS_CLANG_NEWER_THAN(18)
1769
+ InsertTemplateArg (nonTmplParam->getDefaultArgument ().getArgument ());
1770
+ #else
1755
1771
InsertArg (nonTmplParam->getDefaultArgument ());
1772
+ #endif
1756
1773
}
1757
1774
} else {
1758
1775
mOutputFormatHelper .Append (typeName, EllipsisSpace (nonTmplParam->isParameterPack ()));
@@ -3008,9 +3025,29 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
3008
3025
mOutputFormatHelper .Append (kwUsingSpace, GetName (*stmt), hlpAssing);
3009
3026
3010
3027
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
3011
3047
if (const auto * elaboratedType = underlyingType->getAs <ElaboratedType>()) {
3012
3048
InsertNamespace (elaboratedType->getQualifier ());
3013
3049
}
3050
+ #endif
3014
3051
3015
3052
StringStream stream{};
3016
3053
stream.Print (*templateSpecializationType);
@@ -3686,7 +3723,10 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
3686
3723
3687
3724
// attributes start with a space, skip it as it is not required for the first attribute
3688
3725
std::string_view start{stream.str ()};
3726
+ #if IS_CLANG_NEWER_THAN(18)
3727
+ #else
3689
3728
start.remove_prefix (1 );
3729
+ #endif
3690
3730
3691
3731
mOutputFormatHelper .Append (start, " " sv);
3692
3732
}
@@ -4426,12 +4466,20 @@ void CodeGenerator::InsertSuffix(const QualType& type)
4426
4466
4427
4467
void CodeGenerator::InsertTemplateArgs (const ClassTemplateSpecializationDecl& clsTemplateSpe)
4428
4468
{
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
4429
4476
if (const TypeSourceInfo* typeAsWritten = clsTemplateSpe.getTypeAsWritten ()) {
4430
4477
const TemplateSpecializationType* tmplSpecType = cast<TemplateSpecializationType>(typeAsWritten->getType ());
4431
4478
InsertTemplateArgs (*tmplSpecType);
4432
4479
} else {
4433
4480
InsertTemplateArgs (clsTemplateSpe.getTemplateArgs ());
4434
4481
}
4482
+ #endif
4435
4483
}
4436
4484
// -----------------------------------------------------------------------------
4437
4485
0 commit comments