cxx-default-args.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // PR6647
  3. class C {
  4. // After the error, the rest of the tokens inside the default arg should be
  5. // skipped, avoiding a "expected ';' after class" after 'undecl'.
  6. void m(int x = undecl + 0); // expected-error {{use of undeclared identifier 'undecl'}}
  7. };
  8. typedef struct Inst {
  9. void m(int x=0);
  10. } *InstPtr;
  11. struct X {
  12. void f(int x = 1:); // expected-error {{unexpected end of default argument expression}}
  13. };
  14. // PR13657
  15. struct T {
  16. template <typename A, typename B> struct T1 { enum {V};};
  17. template <int A, int B> struct T2 { enum {V}; };
  18. template <int, int> static int func(int);
  19. void f1(T1<int, int> = T1<int, int>());
  20. void f2(T1<int, double> = T1<int, double>(), T2<0, 5> = T2<0, 5>());
  21. void f3(int a = T2<0, (T1<int, int>::V > 10) ? 5 : 6>::V, bool b = 4<5 );
  22. void f4(bool a = 1 < 0, bool b = 2 > 0 );
  23. void f5(bool a = 1 > T2<0, 0>::V, bool b = T1<int,int>::V < 3, int c = 0);
  24. void f6(bool a = T2<0,3>::V < 4, bool b = 4 > T2<0,3>::V);
  25. void f7(bool a = T1<int, bool>::V < 3);
  26. void f8(int = func<0,1<2>(0), int = 1<0, T1<int,int>(int) = 0);
  27. };
  28. // rdar://18508589
  29. struct S {
  30. void f(int &r = error); // expected-error {{use of undeclared identifier 'error'}}
  31. };
  32. struct U {
  33. void i(int x = ) {} // expected-error{{expected expression}}
  34. typedef int *fp(int x = ); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
  35. };