]> granicus.if.org Git - clang/commitdiff
[c++1z] Tests for class template argument deduction in dependent contexts.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 10 Feb 2017 23:10:17 +0000 (23:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 10 Feb 2017 23:10:17 +0000 (23:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294802 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

index 33f2c72045311ab248f0abd80cf62362eba4bd02..4743e38ba1c888ae44972aaddd9bcfb033e0f4d6 100644 (file)
@@ -87,3 +87,33 @@ namespace deprecated {
   [[deprecated]] A(int) -> A<void>; // expected-note {{marked deprecated here}}
   A a = 0; // expected-warning {{'<deduction guide for A>' is deprecated}}
 }
+
+namespace dependent {
+  template<template<typename...> typename A> decltype(auto) a = A{1, 2, 3};
+  static_assert(has_type<vector<int>>(a<vector>));
+  static_assert(has_type<tuple<int, int, int>>(a<tuple>));
+
+  struct B {
+    template<typename T> struct X { X(T); };
+    X(int) -> X<int>;
+    template<typename T> using Y = X<T>; // expected-note {{template}}
+  };
+  template<typename T> void f() {
+    typename T::X tx = 0;
+    typename T::Y ty = 0; // expected-error {{alias template 'Y' requires template arguments; argument deduction only allowed for class templates}}
+  }
+  template void f<B>(); // expected-note {{in instantiation of}}
+
+  template<typename T> struct C { C(T); };
+  template<typename T> C(T) -> C<T>;
+  template<typename T> void g(T a) {
+    C b = 0;
+    C c = a;
+    using U = decltype(b); // expected-note {{previous}}
+    using U = decltype(c); // expected-error {{different types ('C<const char *>' vs 'C<int>')}}
+  }
+  void h() {
+    g(0);
+    g("foo"); // expected-note {{instantiation of}}
+  }
+}