1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
27b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
37b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregortemplate<typename ...Types> struct tuple;
46e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregortemplate<unsigned> struct unsigned_c;
56e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
66e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregortemplate<typename T, typename U>
76e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregorstruct is_same {
86e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  static const bool value = false;
96e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor};
106e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
116e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregortemplate<typename T>
126e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregorstruct is_same<T, T> {
136e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  static const bool value = true;
146e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor};
157b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
167b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregornamespace PackExpansionNotAtEnd {
177b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  template<typename T, typename U>
187b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  struct tuple_same_with_int {
197b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor    static const bool value = false;
207b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  };
217b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
227b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  template<typename ...Types>
237b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  struct tuple_same_with_int<tuple<Types...>, tuple<Types..., int>> {
247b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor    static const bool value = true;
257b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  };
267b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
277b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  int tuple_same_with_int_1[tuple_same_with_int<tuple<int, float, double>,
287b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor                                                tuple<int, float, double, int>
297b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor                                                >::value? 1 : -1];
307b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
317b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor  template<typename ... Types> struct UselessPartialSpec;
327b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor
336e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  template<typename ... Types, // expected-note{{non-deducible template parameter 'Types'}}
347b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor           typename Tail> // expected-note{{non-deducible template parameter 'Tail'}}
35651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  struct UselessPartialSpec<Types..., Tail>; // expected-warning{{class template partial specialization contains template parameters that cannot be deduced; this partial specialization will never be used}}
367b976ece336d209977b25b5c28ee09c2d2146e6aDouglas Gregor}
376e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
386e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregornamespace DeduceNonTypeTemplateArgsInArray {
396e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  template<typename ...ArrayTypes>
406e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  struct split_arrays;
416e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
426e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  template<typename ...ElementTypes, unsigned ...Bounds>
436e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  struct split_arrays<ElementTypes[Bounds]...> {
446e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor    typedef tuple<ElementTypes...> element_types;
456e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
466e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor    // FIXME: Would like to have unsigned_tuple<Bounds...> here.
476e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor    typedef tuple<unsigned_c<Bounds>...> bounds_types;
486e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  };
496e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor
506e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  int check1[is_same<split_arrays<int[1], float[2], double[3]>::element_types,
516e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor                     tuple<int, float, double>>::value? 1 : -1];
526e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor  int check2[is_same<split_arrays<int[1], float[2], double[3]>::bounds_types,
536e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor                     tuple<unsigned_c<1>, unsigned_c<2>, unsigned_c<3>>
546e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor                     >::value? 1 : -1];
556e4e17de3df88ead7eaf51b3503a6be1718438c0Douglas Gregor}
56030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith
57030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smithnamespace DeduceWithDefaultArgs {
58030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith  template<template<typename...> class Container> void f(Container<int>); // expected-note {{substitution failure [with Container = X]}}
59030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith  template<typename, typename = int> struct X {};
60030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith  void g() {
61030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith    // OK, use default argument for the second template parameter.
62030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith    f(X<int>{});
63030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith    f(X<int, int>{});
64030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith
65030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith    // Not OK.
66030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith    f(X<int, double>{}); // expected-error {{no matching function for call to 'f'}}
67030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith  }
68030a6644f253818b81b4d8a7fc1770c0a3d35474Richard Smith}
69