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