p1b.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // The first run checks that the correct errors are generated,
  2. // implicitly checking the order of default argument parsing:
  3. // RUN: %clang_cc1 -fsyntax-only -verify %s
  4. // The second run checks the order of inline method definitions:
  5. // RUN: not %clang_cc1 -fsyntax-only %s 2> %t
  6. // RUN: FileCheck %s < %t
  7. class A {
  8. public:
  9. void a1() {
  10. B b = B();
  11. }
  12. class B;
  13. void a2(B b = B()); // expected-error{{use of default argument to function 'B' that is declared later in class 'B'}}
  14. void a3(int a = 42);
  15. // CHECK: error: use of undeclared identifier 'first'
  16. void a4(int a = first); // expected-error{{use of undeclared identifier 'first'}}
  17. class B {
  18. public:
  19. B(int b = 42) { // expected-note{{default argument declared here}}
  20. A a;
  21. a.a3();
  22. a.a6();
  23. }
  24. void b1(A a = A()); // expected-error{{use of default argument to function 'A' that is declared later in class 'A'}}
  25. // CHECK: error: use of undeclared identifier 'second'
  26. void b2(int a = second); // expected-error{{use of undeclared identifier 'second'}}
  27. };
  28. void a5() {
  29. B b = B();
  30. }
  31. void a6(B b = B());
  32. A(int a = 42); // expected-note{{default argument declared here}}
  33. // CHECK: error: use of undeclared identifier 'third'
  34. void a7(int a = third); // expected-error{{use of undeclared identifier 'third'}}
  35. };