@@ -9895,26 +9895,30 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
98959895 if (!Template) {
98969896 if (auto *AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>(
98979897 TemplateName.getAsTemplateDecl ())) {
9898- Diag (Kind.getLocation (),
9899- diag::warn_cxx17_compat_ctad_for_alias_templates);
9900- LookupTemplateDecl = AliasTemplate;
9901- auto UnderlyingType = AliasTemplate->getTemplatedDecl ()
9902- ->getUnderlyingType ()
9903- .getCanonicalType ();
9904- // C++ [over.match.class.deduct#3]: ..., the defining-type-id of A must be
9905- // of the form
9906- // [typename] [nested-name-specifier] [template] simple-template-id
9907- if (const auto *TST =
9908- UnderlyingType->getAs <TemplateSpecializationType>()) {
9909- Template = dyn_cast_or_null<ClassTemplateDecl>(
9910- TST->getTemplateName ().getAsTemplateDecl ());
9911- } else if (const auto *RT = UnderlyingType->getAs <RecordType>()) {
9912- // Cases where template arguments in the RHS of the alias are not
9913- // dependent. e.g.
9914- // using AliasFoo = Foo<bool>;
9915- if (const auto *CTSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(
9916- RT->getAsCXXRecordDecl ()))
9917- Template = CTSD->getSpecializedTemplate ();
9898+ if (getLangOpts ().CPlusPlus20 ) {
9899+ LookupTemplateDecl = AliasTemplate;
9900+ auto UnderlyingType = AliasTemplate->getTemplatedDecl ()
9901+ ->getUnderlyingType ()
9902+ .getCanonicalType ();
9903+ // C++ [over.match.class.deduct#3]: ..., the defining-type-id of A must
9904+ // be of the form
9905+ // [typename] [nested-name-specifier] [template] simple-template-id
9906+ if (const auto *TST =
9907+ UnderlyingType->getAs <TemplateSpecializationType>()) {
9908+ Template = dyn_cast_or_null<ClassTemplateDecl>(
9909+ TST->getTemplateName ().getAsTemplateDecl ());
9910+ } else if (const auto *RT = UnderlyingType->getAs <RecordType>()) {
9911+ // Cases where template arguments in the RHS of the alias are not
9912+ // dependent. e.g.
9913+ // using AliasFoo = Foo<bool>;
9914+ if (const auto *CTSD =
9915+ llvm::dyn_cast<ClassTemplateSpecializationDecl>(
9916+ RT->getAsCXXRecordDecl ()))
9917+ Template = CTSD->getSpecializedTemplate ();
9918+ }
9919+ } else {
9920+ Diag (Kind.getLocation (),
9921+ diag::warn_cxx17_compat_ctad_for_alias_templates);
99189922 }
99199923 }
99209924 }
0 commit comments