[clang] [clang] NFC: add a few template template parameter test cases (PR #160230)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 22 22:05:43 PDT 2025


https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/160230

>From 554e56ed87e2ea7b6ab592b5593512f4b86d528c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Tue, 23 Sep 2025 01:23:35 -0300
Subject: [PATCH] [clang] NFC: add a few template template parameter test cases

I also posted these on the core reflector today.
---
 clang/test/SemaTemplate/cwg2398.cpp           | 19 +++++++++++++++
 clang/test/SemaTemplate/temp_arg_template.cpp | 23 +++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/clang/test/SemaTemplate/cwg2398.cpp b/clang/test/SemaTemplate/cwg2398.cpp
index 06333c81a603e..315fa952932c5 100644
--- a/clang/test/SemaTemplate/cwg2398.cpp
+++ b/clang/test/SemaTemplate/cwg2398.cpp
@@ -672,3 +672,22 @@ namespace nttp_partial_order {
     template void f<B>(B<nullptr>);
   } // namespace t6
 } // namespace nttp_partial_order
+
+namespace nttp_inconsistent {
+  namespace t1 {
+    template<class A, A B> struct X {};
+    // expected-error at -1 {{conflicting deduction 'C' against 'int' for parameter}}
+    template<template<class C, int D> class TT> struct Y {};
+    // expected-note at -1 {{previous template template parameter is here}}
+    template struct Y<X>;
+    // expected-note at -1 {{has different template parameters}}
+  } // namespace t1
+  namespace t2 {
+    template<class A, A B = 0> struct X {};
+    // expected-error at -1 {{conflicting deduction 'C' against 'int' for parameter}}
+    template<template<class C> class TT> struct Y {};
+    // expected-note at -1 {{previous template template parameter is here}}
+    template struct Y<X>;
+    // expected-note at -1 {{has different template parameters}}
+  } // namespace t2
+} // namespace nttp_inconsistent
diff --git a/clang/test/SemaTemplate/temp_arg_template.cpp b/clang/test/SemaTemplate/temp_arg_template.cpp
index c9576e2057e53..73fa57beebe11 100644
--- a/clang/test/SemaTemplate/temp_arg_template.cpp
+++ b/clang/test/SemaTemplate/temp_arg_template.cpp
@@ -168,3 +168,26 @@ namespace PR10147 {
   template<template<typename...> class A> void f(A<int>*) { A<> a; } // expected-warning 0-1{{extension}}
   void g() { f((A<>*)0); }
 }
+
+#if __cplusplus >= 201703L
+namespace multiple_conversions {
+  constexpr int g = 1;
+  struct Z {
+      constexpr operator const int&() const { return g; }
+      constexpr operator int() { return 2; }
+  } z;
+
+  template<template<const int&> class TT> struct A {
+    static constexpr int value = TT<z>::value;
+  };
+
+  template<int I> struct B {
+    static constexpr int value = I;
+  };
+  // FIXME: This should probably convert z to (const int &) first, then
+  // convert that to int.
+  static_assert(A<B>::value == 1);
+  // cxx17-error at -1 {{static assertion failed}}
+  // cxx17-note at -2 {{expression evaluates to '2 == 1'}}
+} // namespace multiple_conversions
+#endif



More information about the cfe-commits mailing list