1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Wno-uninitialized -std=c++11 -verify %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc template<int> struct c { c(int) = delete; typedef void val; operator int() const; }; 4f4a2713aSLionel Sambuc 5f4a2713aSLionel Sambuc int val; 6f4a2713aSLionel Sambuc int foobar; 7f4a2713aSLionel Sambuc struct S { 8f4a2713aSLionel Sambuc int k1 = a < b < c, d > ::val, e1; 9f4a2713aSLionel Sambuc int k2 = a < b, c < d > ::val, e2; 10f4a2713aSLionel Sambuc int k3 = b < a < c, d > ::val, e3; 11f4a2713aSLionel Sambuc int k4 = b < c, x, y = d > ::val, e4; 12f4a2713aSLionel Sambuc int k5 = T1 < b, &S::operator=(int); // expected-error {{extra qualification}} 13f4a2713aSLionel Sambuc int k6 = T2 < b, &S::operator= >::val; 14f4a2713aSLionel Sambuc int k7 = T1 < b, &S::operator>(int); // expected-error {{extra qualification}} 15f4a2713aSLionel Sambuc int k8 = T2 < b, &S::operator> >::val; 16f4a2713aSLionel Sambuc int k9 = T3 < a < b, c >> (d), e5 = 1 > (e4); 17f4a2713aSLionel Sambuc int k10 = 0 < T3 < a < b, c >> (d 18f4a2713aSLionel Sambuc ) // expected-error {{expected ';' at end of declaration}} 19f4a2713aSLionel Sambuc , a > (e4); 20f4a2713aSLionel Sambuc int k11 = 0 < 1, c<3>::*ptr; 21f4a2713aSLionel Sambuc int k12 = e < 0, int a<b<c>::* >(), e11; 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambuc void f1( 24f4a2713aSLionel Sambuc int k1 = a < b < c, d > ::val, 25f4a2713aSLionel Sambuc int k2 = b < a < c, d > ::val, 26f4a2713aSLionel Sambuc int k3 = b < c, int x = 0 > ::val, 27f4a2713aSLionel Sambuc int k4 = a < b, T3 < int > >(), // expected-error {{must be an expression}} 28f4a2713aSLionel Sambuc int k5 = a < b, c < d > ::val, 29f4a2713aSLionel Sambuc int k6 = a < b, c < d > (n) // expected-error {{undeclared identifier 'n'}} 30f4a2713aSLionel Sambuc ); 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc void f2a( 33f4a2713aSLionel Sambuc // T3<int> here is a parameter type, so must be declared before it is used. 34f4a2713aSLionel Sambuc int k1 = c < b, T3 < int > x = 0 // expected-error {{unexpected end of default argument expression}} 35f4a2713aSLionel Sambuc ); 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc template<typename, int=0> struct T3 { T3(int); operator int(); }; 38f4a2713aSLionel Sambuc 39f4a2713aSLionel Sambuc void f2b( 40f4a2713aSLionel Sambuc int k1 = c < b, T3 < int > x = 0 // ok 41f4a2713aSLionel Sambuc ); 42f4a2713aSLionel Sambuc 43f4a2713aSLionel Sambuc // This is a one-parameter function. Ensure we don't typo-correct it to 44f4a2713aSLionel Sambuc // int = a < b, c < foobar > () 45f4a2713aSLionel Sambuc // ... which would be a function with two parameters. 46f4a2713aSLionel Sambuc int f3(int = a < b, c < goobar > ()); 47f4a2713aSLionel Sambuc static constexpr int (S::*f3_test)(int) = &S::f3; 48f4a2713aSLionel Sambuc 49f4a2713aSLionel Sambuc void f4( 50f4a2713aSLionel Sambuc int k1 = a<1,2>::val, 51f4a2713aSLionel Sambuc int missing_default // expected-error {{missing default argument on parameter}} 52f4a2713aSLionel Sambuc ); 53f4a2713aSLionel Sambuc 54f4a2713aSLionel Sambuc void f5( 55f4a2713aSLionel Sambuc int k1 = b < c, 56f4a2713aSLionel Sambuc int missing_default // expected-error {{missing default argument on parameter}} 57f4a2713aSLionel Sambuc ); 58f4a2713aSLionel Sambuc 59f4a2713aSLionel Sambuc void f6( 60f4a2713aSLionel Sambuc int k = b < c, 61f4a2713aSLionel Sambuc unsigned int (missing_default) // expected-error {{missing default argument on parameter}} 62f4a2713aSLionel Sambuc ); 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc template<int, int=0> struct a { static const int val = 0; operator int(); }; // expected-note {{here}} 65f4a2713aSLionel Sambuc static const int b = 0, c = 1, d = 2, goobar = 3; 66f4a2713aSLionel Sambuc template<int, typename> struct e { operator int(); }; 67f4a2713aSLionel Sambuc 68f4a2713aSLionel Sambuc int mp1 = 0 < 1, 69f4a2713aSLionel Sambuc a<b<c,b<c>::*mp2, 70f4a2713aSLionel Sambuc mp3 = 0 > a<b<c>::val, 71f4a2713aSLionel Sambuc a<b<c,b<c>::*mp4 = 0, 72f4a2713aSLionel Sambuc a<b<c,b<c>::*mp5 {0}, 73f4a2713aSLionel Sambuc a<b<c,b<c>::*mp6; 74f4a2713aSLionel Sambuc 75f4a2713aSLionel Sambuc int np1 = e<0, int a<b<c,b<c>::*>(); 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambuc static const int T1 = 4; 78f4a2713aSLionel Sambuc template<int, int &(S::*)(int)> struct T2 { static const int val = 0; }; 79f4a2713aSLionel Sambuc }; 80f4a2713aSLionel Sambuc 81f4a2713aSLionel Sambuc namespace NoAnnotationTokens { 82f4a2713aSLionel Sambuc template<bool> struct Bool { Bool(int); }; 83f4a2713aSLionel Sambuc static const bool in_class = false; 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc struct Test { 86f4a2713aSLionel Sambuc // Check we don't keep around a Bool<false> annotation token here. 87f4a2713aSLionel Sambuc int f(Bool<true> = X<Y, Bool<in_class> >(0)); 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc // But it's OK if we do here. 90f4a2713aSLionel Sambuc int g(Bool<true> = Z<Y, Bool<in_class> = Bool<false>(0)); 91f4a2713aSLionel Sambuc 92f4a2713aSLionel Sambuc static const bool in_class = true; 93f4a2713aSLionel Sambuc template<int, typename U> using X = U; 94f4a2713aSLionel Sambuc static const int Y = 0, Z = 0; 95f4a2713aSLionel Sambuc }; 96f4a2713aSLionel Sambuc } 97f4a2713aSLionel Sambuc 98f4a2713aSLionel Sambuc namespace ImplicitInstantiation { 99f4a2713aSLionel Sambuc template<typename T> struct HasError { typename T::error error; }; // expected-error {{has no members}} 100f4a2713aSLionel Sambuc 101f4a2713aSLionel Sambuc struct S { 102f4a2713aSLionel Sambuc // This triggers the instantiation of the outer HasError<int> during 103f4a2713aSLionel Sambuc // disambiguation, even though it uses the inner HasError<int>. 104f4a2713aSLionel Sambuc void f(int a = X<Y, HasError<int>::Z >()); // expected-note {{in instantiation of}} 105f4a2713aSLionel Sambuc 106f4a2713aSLionel Sambuc template<typename, typename> struct X { operator int(); }; 107f4a2713aSLionel Sambuc typedef int Y; 108f4a2713aSLionel Sambuc template<typename> struct HasError { typedef int Z; }; 109f4a2713aSLionel Sambuc }; 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambuc HasError<int> hei; 112f4a2713aSLionel Sambuc } 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc namespace CWG325 { 115f4a2713aSLionel Sambuc template <int A, typename B> struct T { static int i; operator int(); }; 116f4a2713aSLionel Sambuc class C { 117f4a2713aSLionel Sambuc int Foo (int i = T<1, int>::i); 118f4a2713aSLionel Sambuc }; 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc class D { 121f4a2713aSLionel Sambuc int Foo (int i = T<1, int>::i); 122f4a2713aSLionel Sambuc template <int A, typename B> struct T {static int i;}; 123f4a2713aSLionel Sambuc }; 124f4a2713aSLionel Sambuc 125f4a2713aSLionel Sambuc const int a = 0; 126f4a2713aSLionel Sambuc typedef int b; 127f4a2713aSLionel Sambuc T<a,b> c; 128f4a2713aSLionel Sambuc struct E { 129f4a2713aSLionel Sambuc int n = T<a,b>(c); 130f4a2713aSLionel Sambuc }; 131f4a2713aSLionel Sambuc } 132f4a2713aSLionel Sambuc 133f4a2713aSLionel Sambuc namespace Operators { 134f4a2713aSLionel Sambuc struct Y {}; operator ,(const Y &,const Y &)135f4a2713aSLionel Sambuc constexpr int operator,(const Y&, const Y&) { return 8; } operator >(const Y &,const Y &)136f4a2713aSLionel Sambuc constexpr int operator>(const Y&, const Y&) { return 8; } operator <(const Y &,const Y &)137f4a2713aSLionel Sambuc constexpr int operator<(const Y&, const Y&) { return 8; } operator >>(const Y &,const Y &)138f4a2713aSLionel Sambuc constexpr int operator>>(const Y&, const Y&) { return 8; } 139f4a2713aSLionel Sambuc 140f4a2713aSLionel Sambuc struct X { 141f4a2713aSLionel Sambuc typedef int (*Fn)(const Y&, const Y&); 142f4a2713aSLionel Sambuc 143f4a2713aSLionel Sambuc Fn a = operator,, b = operator<, c = operator>; 144f4a2713aSLionel Sambuc void f(Fn a = operator,, Fn b = operator<, Fn c = operator>); 145f4a2713aSLionel Sambuc 146f4a2713aSLionel Sambuc int k1 = T1<0, operator<, operator>, operator<>::val, l1; 147f4a2713aSLionel Sambuc int k2 = T1<0, operator>, operator,, operator,>::val, l2; 148f4a2713aSLionel Sambuc int k3 = T2<0, operator,(Y{}, Y{}), operator<(Y{}, Y{})>::val, l3; 149f4a2713aSLionel Sambuc int k4 = T2<0, operator>(Y{}, Y{}), operator,(Y{}, Y{})>::val, l4; 150f4a2713aSLionel Sambuc int k5 = T3<0, operator>>>::val, l5; 151f4a2713aSLionel Sambuc int k6 = T4<0, T3<0, operator>>>>::val, l6; 152f4a2713aSLionel Sambuc 153f4a2713aSLionel Sambuc template<int, Fn, Fn, Fn> struct T1 { enum { val }; }; 154f4a2713aSLionel Sambuc template<int, int, int> struct T2 { enum { val }; }; 155f4a2713aSLionel Sambuc template<int, Fn> struct T3 { enum { val }; }; 156f4a2713aSLionel Sambuc template<int, typename T> struct T4 : T {}; 157f4a2713aSLionel Sambuc }; 158f4a2713aSLionel Sambuc } 159f4a2713aSLionel Sambuc 160f4a2713aSLionel Sambuc namespace ElaboratedTypeSpecifiers { 161f4a2713aSLionel Sambuc struct S { 162f4a2713aSLionel Sambuc int f(int x = T<a, struct S>()); 163f4a2713aSLionel Sambuc int g(int x = T<a, class __declspec() C>()); 164f4a2713aSLionel Sambuc int h(int x = T<a, union __attribute__(()) U>()); 165f4a2713aSLionel Sambuc int i(int x = T<a, enum E>()); 166f4a2713aSLionel Sambuc int j(int x = T<a, struct S::template T<0, enum E>>()); 167f4a2713aSLionel Sambuc template <int, typename> struct T { operator int(); }; 168f4a2713aSLionel Sambuc static const int a = 0; 169f4a2713aSLionel Sambuc enum E {}; 170f4a2713aSLionel Sambuc }; 171f4a2713aSLionel Sambuc } 172*0a6a1f1dSLionel Sambuc 173*0a6a1f1dSLionel Sambuc namespace PR20459 { 174*0a6a1f1dSLionel Sambuc template <typename EncTraits> struct A { 175*0a6a1f1dSLionel Sambuc void foo(int = EncTraits::template TypeEnc<int, int>::val); // ok 176*0a6a1f1dSLionel Sambuc }; 177*0a6a1f1dSLionel Sambuc } 178