r294802 - [c++1z] Tests for class template argument deduction in dependent contexts.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 10 15:10:17 PST 2017


Author: rsmith
Date: Fri Feb 10 17:10:17 2017
New Revision: 294802

URL: http://llvm.org/viewvc/llvm-project?rev=294802&view=rev
Log:
[c++1z] Tests for class template argument deduction in dependent contexts.

Modified:
    cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=294802&r1=294801&r2=294802&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Fri Feb 10 17:10:17 2017
@@ -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}}
+  }
+}




More information about the cfe-commits mailing list