https://github.com/GeorgeKA updated 
https://github.com/llvm/llvm-project/pull/133806

>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 1/2] 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>;

>From c48c4a60c1ed8aebff27bf8a7bb108dd3a9ad3ef Mon Sep 17 00:00:00 2001
From: George Asante <gkasa...@gmail.com>
Date: Mon, 31 Mar 2025 18:38:06 -0400
Subject: [PATCH 2/2] Switched to using multiclasses for both messages

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 14 ++------------
 clang/lib/Sema/SemaInit.cpp                      |  4 ++--
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6f71628f19a4a..79389eebd81f1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -49,6 +49,8 @@ defm constexpr_ctor_missing_init : CXX20Compat<
 defm adl_only_template_id : CXX20Compat<
   "use of function template name with no prior declaration in function call "
   "with explicit template arguments is">;
+defm ctad_for_alias_templates
+    : CXX20Compat<"class template argument deduction for alias templates is">;
 
 // C++23 compatibility with C++20 and earlier.
 defm constexpr_static_var : CXX23Compat<
@@ -8442,18 +8444,6 @@ let CategoryName = "Lambda Issue" in {
   def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
     "%select{default construction|assignment}0 of lambda is incompatible with "
     "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 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 7229cd42f85d0..a7e09f851214a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9897,8 +9897,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
             TemplateName.getAsTemplateDecl())) {
       Diag(Kind.getLocation(),
            getLangOpts().CPlusPlus20
-               ? diag::warn_cxx17_compat_ctad_for_alias_templates
-               : diag::ext_ctad_for_alias_templates_cxx20);
+               ? diag::compat_cxx20_ctad_for_alias_templates
+               : diag::compat_pre_cxx20_ctad_for_alias_templates);
       LookupTemplateDecl = AliasTemplate;
       auto UnderlyingType = AliasTemplate->getTemplatedDecl()
                                 ->getUnderlyingType()

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to