[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 9 06:16:00 PDT 2025


================
@@ -35,31 +35,27 @@ namespace ConstDestruction {
 
     constexpr ~D() {
       if (!can_destroy)
-        throw "oh no"; // expected-note {{subexpression not valid}}
+        throw "oh no";
     }
   };
 
-  template<D d>
-  void f() {} // expected-note 2{{invalid explicitly-specified argument}}
+  template<D d> // expected-note 2{{template parameter is declared here}}
+  void f() {} // expected-note 2{{candidate template ignored: invalid explicitly-specified argument}}
 
   void g() {
     f<D{0, true}>();
     f<D{0, false}>(); // expected-error {{no matching function}}
   }
 
   // We can SFINAE on constant destruction.
-  template<typename T> auto h(T t) -> decltype(f<T{1, false}>());
-  template<typename T> auto h(T t) -> decltype(f<T{1, true}>());
+  // template<typename T> auto h(T t) -> decltype(f<T{1, false}>());
+  // template<typename T> auto h(T t) -> decltype(f<T{1, true}>());
 
   void i() {
-    h(D());
+    //h(D());
     // Ensure we don't cache an invalid template argument after we've already
     // seen it in a SFINAE context.
     f<D{1, false}>(); // expected-error {{no matching function}}
     f<D{1, true}>();
   }
-
-  template<D d> struct Z {};
-  Z<D{2, true}> z1;
-  Z<D{2, false}> z2; // expected-error {{non-type template argument is not a constant expression}} expected-note-re {{in call to '{{.*}}.~D()'}}
----------------
mizvekov wrote:

What is up with these commented and removed tests?

https://github.com/llvm/llvm-project/pull/122754


More information about the cfe-commits mailing list