Richard Smith | 9ca5c42 | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s |
Andy Gibbs | c6e68da | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
Douglas Gregor | 5c80a27b | 2009-11-25 18:55:14 +0000 | [diff] [blame] | 3 | |
| 4 | // Test default template arguments for function templates. |
| 5 | template<typename T = int> |
| 6 | void f0(); |
| 7 | |
| 8 | template<typename T> |
| 9 | void f0(); |
| 10 | |
| 11 | void g0() { |
| 12 | f0(); // okay! |
| 13 | } |
| 14 | |
| 15 | template<typename T, int N = T::value> |
| 16 | int &f1(T); |
| 17 | |
| 18 | float &f1(...); |
| 19 | |
| 20 | struct HasValue { |
| 21 | static const int value = 17; |
| 22 | }; |
| 23 | |
| 24 | void g1() { |
| 25 | float &fr = f1(15); |
| 26 | int &ir = f1(HasValue()); |
| 27 | } |
David Majnemer | 8918920 | 2013-08-28 23:48:32 +0000 | [diff] [blame] | 28 | |
| 29 | namespace PR16689 { |
| 30 | template <typename T1, typename T2> class tuple { |
| 31 | public: |
| 32 | template <typename = T2> |
| 33 | constexpr tuple() {} |
| 34 | }; |
| 35 | template <class X, class... Y> struct a : public X { |
| 36 | using X::X; |
| 37 | }; |
| 38 | auto x = a<tuple<int, int> >(); |
| 39 | } |
| 40 | |
| 41 | namespace PR16975 { |
| 42 | template <typename...> struct is { |
| 43 | constexpr operator bool() const { return false; } |
| 44 | }; |
| 45 | |
| 46 | template <typename... Types> |
| 47 | struct bar { |
| 48 | template <typename T, |
| 49 | bool = is<Types...>()> |
| 50 | bar(T); |
| 51 | }; |
| 52 | |
| 53 | struct baz : public bar<> { |
| 54 | using bar::bar; |
| 55 | }; |
| 56 | |
| 57 | baz data{0}; |
| 58 | } |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 59 | |
| 60 | // rdar://23810407 |
| 61 | // An IRGen failure due to a symbol collision due to a default argument |
| 62 | // being instantiated twice. Credit goes to Richard Smith for this |
| 63 | // reduction to a -fsyntax-only failure. |
| 64 | namespace rdar23810407 { |
| 65 | // Instantiating the default argument multiple times will produce two |
| 66 | // different lambda types and thus instantiate this function multiple |
| 67 | // times, which will produce conflicting extern variable declarations. |
| 68 | template<typename T> int f(T t) { |
| 69 | extern T rdar23810407_variable; |
| 70 | return 0; |
| 71 | } |
| 72 | template<typename T> int g(int a = f([] {})); |
| 73 | void test() { |
| 74 | g<int>(); |
| 75 | g<int>(); |
| 76 | } |
| 77 | } |
Manman Ren | c445d38 | 2016-02-24 23:05:43 +0000 | [diff] [blame] | 78 | |
| 79 | // rdar://problem/24480205 |
| 80 | namespace PR13986 { |
| 81 | constexpr unsigned Dynamic = 0; |
| 82 | template <unsigned> class A { template <unsigned = Dynamic> void m_fn1(); }; |
| 83 | class Test { |
| 84 | ~Test() {} |
| 85 | A<1> m_target; |
| 86 | }; |
| 87 | } |