Add tests for function conversions in conversion function template
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 12 Jul 2018 18:49:13 +0000 (18:49 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 12 Jul 2018 18:49:13 +0000 (18:49 +0000)
deduction.

llvm-svn: 336931

clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p4.cpp

index 5c3f2ca..8ae2213 100644 (file)
@@ -1645,6 +1645,9 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
         }
       }
       // FIXME: Detect non-deduced exception specification mismatches?
+      //
+      // Careful about [temp.deduct.call] and [temp.deduct.conv], which allow
+      // top-level differences in noexcept-specifications.
 
       return Sema::TDK_Success;
     }
index 89478ed..085976b 100644 (file)
@@ -129,4 +129,21 @@ 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
+
+#if __cplusplus >= 201702L
+  template<bool Noexcept, typename T, typename ...U> using Function = T(U...) noexcept(Noexcept);
+  template<bool Noexcept> struct ConvToFunction {
+    template <typename T, typename ...U> operator Function<Noexcept, T, U...>&(); // expected-note {{candidate}}
+  };
+  void (&fn1)(int) noexcept(false) = ConvToFunction<false>();
+  void (&fn2)(int) noexcept(true)  = ConvToFunction<false>(); // expected-error {{no viable}}
+  void (&fn3)(int) noexcept(false) = ConvToFunction<true>();
+  void (&fn4)(int) noexcept(true)  = ConvToFunction<true>();
+
+  struct ConvToFunctionDeducingNoexcept {
+    template <bool Noexcept, typename T, typename ...U> operator Function<Noexcept, T, U...>&();
+  };
+  void (&fn5)(int) noexcept(false) = ConvToFunctionDeducingNoexcept();
+  void (&fn6)(int) noexcept(true)  = ConvToFunctionDeducingNoexcept();
+#endif
 }