[clang] [clang][test] Add test for incompatible cv-qualified reference types in conversion function template (PR #81950)

Duo Wang via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 15 16:32:42 PST 2024


https://github.com/wdunicornpro created https://github.com/llvm/llvm-project/pull/81950

We currently lack test coverage for [SemaTemplateDeduction.cpp#L1619-L1620](https://github.com/llvm/llvm-project/blob/fe20a75/clang/lib/Sema/SemaTemplateDeduction.cpp#L1619-L1629), which handles the case where both the P type and the A type are reference types but A is more cv-qualified than P. This is deemed non-deduced unless both A and P are possibly cv-qualified forms of the template parameter T. This PR adds tests for that logic.

>From ec34c9f2fe6713d0301a56fd28e4b94cc563c96a Mon Sep 17 00:00:00 2001
From: Duo Wang <Duo.Wang at sony.com>
Date: Thu, 15 Feb 2024 14:36:10 -0800
Subject: [PATCH] [clang][test] Add test for incompatible cv-qualified
 reference types in conversion function template

---
 .../temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp    | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp
index 085976b081332b..974240c514846c 100644
--- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp
@@ -130,6 +130,15 @@ namespace non_ptr_ref_cv_qual {
   int (&test_conv_to_arr_1)[3] = ConvToArr(); // ok
   const int (&test_conv_to_arr_2)[3] = ConvToArr(); // ok, with qualification conversion
 
+  struct ConvToConstArr {
+    template <int N>
+    operator const Arr<int, N> &() { // expected-note {{candidate}}
+      static_assert(N == 3, "");
+    }
+  };
+  Arr<int, 3> &test_conv_to_const_arr_1 = ConvToConstArr(); // expected-error {{no viable}}
+  const Arr<int, 3> &test_conv_to_const_arr_2 = ConvToConstArr(); // ok
+
 #if __cplusplus >= 201702L
   template<bool Noexcept, typename T, typename ...U> using Function = T(U...) noexcept(Noexcept);
   template<bool Noexcept> struct ConvToFunction {



More information about the cfe-commits mailing list