1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
3 // expected-no-diagnostics
5 // Test default template arguments for function templates.
6 template<typename T
= int>
16 template<typename T
, int N
= T::value
>
22 static const int value
= 17;
27 int &ir
= f1(HasValue());
31 template <typename T1
, typename T2
> class tuple
{
33 template <typename
= T2
>
36 template <class X
, class... Y
> struct a
: public X
{
39 auto x
= a
<tuple
<int, int> >();
43 template <typename
...> struct is
{
44 constexpr operator bool() const { return false; }
47 template <typename
... Types
>
50 bool = is
<Types
...>()>
56 struct baz
: public bar
<> {
64 // An IRGen failure due to a symbol collision due to a default argument
65 // being instantiated twice. Credit goes to Richard Smith for this
66 // reduction to a -fsyntax-only failure.
67 namespace rdar23810407
{
68 // Instantiating the default argument multiple times will produce two
69 // different lambda types and thus instantiate this function multiple
70 // times, which will produce conflicting extern variable declarations.
71 template<typename T
> int f(T t
) {
72 extern T rdar23810407_variable
;
75 template<typename T
> int g(int a
= f([] {}));
82 // rdar://problem/24480205
84 constexpr unsigned Dynamic
= 0;
85 template <unsigned> class A
{ template <unsigned = Dynamic
> void m_fn1(); };
92 // rdar://problem/34167492
93 // Template B is instantiated during checking if defaulted A copy constructor
94 // is constexpr. For this we check if S<int> copy constructor is constexpr. And
95 // for this we check S constructor template with default argument that mentions
96 // template B. In turn, template instantiation triggers checking defaulted
97 // members exception spec. The problem is that it checks defaulted members not
98 // for instantiated class only, but all defaulted members so far. In this case
99 // we try to check exception spec for A default constructor which requires
100 // initializer for the field _a. But initializers are added after constexpr
101 // check so we reject the code because cannot find _a initializer.
102 namespace rdar34167492
{
103 template <typename T
> struct B
{ using type
= bool; };
105 template <typename T
> struct S
{
108 template <typename U
, typename B
<U
>::type
= true>
109 S(const S
<U
>&) noexcept
;
113 A() noexcept
= default;
114 A(const A
&) noexcept
= default;
119 #if __cplusplus >= 201402L
121 // Verify that a default argument in a lambda can refer to the type of a
122 // previous `auto` argument without crashing.
125 (void) [](auto c
, int x
= sizeof(decltype(c
))) {};
130 } // namespace lambda