p7.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // RUN: %clang_cc1 -verify -std=c++1y %s
  2. // Example from the standard.
  3. namespace X {
  4. void p() {
  5. q(); // expected-error {{undeclared}}
  6. extern void q();
  7. }
  8. void middle() {
  9. q(); // expected-error {{undeclared}}
  10. }
  11. void q() { /*...*/ }
  12. void bottom() {
  13. q();
  14. }
  15. }
  16. int q();
  17. namespace Test1 {
  18. void f() {
  19. extern int a; // expected-note {{previous}}
  20. int g(void); // expected-note {{previous}}
  21. }
  22. double a; // expected-error {{different type: 'double' vs 'int'}}
  23. double g(); // expected-error {{differ only in their return type}}
  24. }
  25. namespace Test2 {
  26. void f() {
  27. extern int a; // expected-note {{previous}}
  28. int g(void); // expected-note {{previous}}
  29. }
  30. void h() {
  31. extern double a; // expected-error {{different type: 'double' vs 'int'}}
  32. double g(void); // expected-error {{differ only in their return type}}
  33. }
  34. }
  35. namespace Test3 {
  36. constexpr void (*f())() {
  37. void h();
  38. return &h;
  39. }
  40. constexpr void (*g())() {
  41. void h();
  42. return &h;
  43. }
  44. static_assert(f() == g(), "");
  45. }
  46. namespace Test4 {
  47. template<typename T>
  48. constexpr void (*f())() {
  49. void h();
  50. return &h;
  51. }
  52. static_assert(f<int>() == f<char>(), "");
  53. void h();
  54. static_assert(f<int>() == &h, "");
  55. }
  56. namespace Test5 {
  57. constexpr auto f() -> void (*)() {
  58. void g();
  59. struct X {
  60. friend void g();
  61. static constexpr auto h() -> void (*)() { return g; }
  62. };
  63. return X::h();
  64. }
  65. void g();
  66. static_assert(f() == g, "");
  67. }