https://github.com/GeorgeKA created https://github.com/llvm/llvm-project/pull/133806
Alias template class template argument deduction is a documented C++20 feature. C++17 also happens to support it, but there is no message output to indicate the officially supported version. This PR adds that. Also updated relevant CTAD test cases. PR for https://github.com/llvm/llvm-project/issues/125913 >From dd978982b2ab41d3d2a55abb448e653a80158ecd Mon Sep 17 00:00:00 2001 From: George Asante <gkasa...@gmail.com> Date: Mon, 31 Mar 2025 17:41:20 -0400 Subject: [PATCH] Add warning message for C++17 alias template CTAD --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 13 ++++++++++--- clang/lib/Sema/SemaInit.cpp | 4 +++- clang/test/SemaCXX/cxx17-compat.cpp | 2 +- .../cxx1z-class-template-argument-deduction.cpp | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index c77cde297dc32..6f71628f19a4a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8444,9 +8444,16 @@ let CategoryName = "Lambda Issue" in { "C++ standards before C++20">, InGroup<CXXPre20Compat>, DefaultIgnore; // C++20 class template argument deduction for alias templates. - def warn_cxx17_compat_ctad_for_alias_templates : Warning< - "class template argument deduction for alias templates is incompatible with " - "C++ standards before C++20">, InGroup<CXXPre20Compat>, DefaultIgnore; + def warn_cxx17_compat_ctad_for_alias_templates + : Warning<"class template argument deduction for alias templates is " + "incompatible with " + "C++ standards before C++20">, + InGroup<CXXPre20Compat>, + DefaultIgnore; + def ext_ctad_for_alias_templates_cxx20 + : ExtWarn<"class template argument deduction for alias templates is a " + "C++20 extension">, + InGroup<CXX20>; } def err_return_in_captured_stmt : Error< diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index cea121d576c5c..7229cd42f85d0 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9896,7 +9896,9 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( if (auto *AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>( TemplateName.getAsTemplateDecl())) { Diag(Kind.getLocation(), - diag::warn_cxx17_compat_ctad_for_alias_templates); + getLangOpts().CPlusPlus20 + ? diag::warn_cxx17_compat_ctad_for_alias_templates + : diag::ext_ctad_for_alias_templates_cxx20); LookupTemplateDecl = AliasTemplate; auto UnderlyingType = AliasTemplate->getTemplatedDecl() ->getUnderlyingType() diff --git a/clang/test/SemaCXX/cxx17-compat.cpp b/clang/test/SemaCXX/cxx17-compat.cpp index 54ea3384022d4..81b3e1fde5493 100644 --- a/clang/test/SemaCXX/cxx17-compat.cpp +++ b/clang/test/SemaCXX/cxx17-compat.cpp @@ -137,7 +137,7 @@ template<typename T> struct A { A(T); }; template<typename T> using B = A<T>; B b = {1}; #if __cplusplus <= 201703L - // FIXME: diagnose as well + // expected-warning@-2 {{class template argument deduction for alias templates is a C++20 extension}} #else // expected-warning@-4 {{class template argument deduction for alias templates is incompatible with C++ standards before C++20}} #endif diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 9aaa13d7ac41a..a7d740e66ba63 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -113,9 +113,9 @@ namespace dependent { }; template<typename T> void f() { typename T::X tx = 0; - typename T::Y ty = 0; + typename T::Y ty = 0; // expected-warning {{class template argument deduction for alias templates is a C++20 extension}} } - template void f<B>(); + template void f<B>(); // expected-note {{in instantiation of function template specialization 'dependent::f<dependent::B>' requested here}} template<typename T> struct C { C(T); }; template<typename T> C(T) -> C<T>; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits