chain-cxx.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Test C++ chained PCH functionality
  2. // Without PCH
  3. // RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s
  4. // With PCH
  5. // RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s
  6. // With modules
  7. // RUN: %clang_cc1 -fsyntax-only -verify -fmodules %s -chain-include %s -chain-include %s
  8. // expected-no-diagnostics
  9. #ifndef HEADER1
  10. #define HEADER1
  11. //===----------------------------------------------------------------------===//
  12. // Primary header for C++ chained PCH test
  13. void f();
  14. // Name not appearing in dependent
  15. void pf();
  16. namespace ns {
  17. void g();
  18. void pg();
  19. }
  20. template <typename T>
  21. struct S { typedef int G; };
  22. // Partially specialize
  23. template <typename T>
  24. struct S<T *> { typedef int H; };
  25. template <typename T> struct TS2;
  26. typedef TS2<int> TS2int;
  27. template <typename T> struct TestBaseSpecifiers { };
  28. template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { };
  29. template <typename T>
  30. struct TS3 {
  31. static const int value = 0;
  32. static const int value2;
  33. };
  34. template <typename T>
  35. const int TS3<T>::value;
  36. template <typename T>
  37. const int TS3<T>::value2 = 1;
  38. // Instantiate struct, but not value.
  39. struct instantiate : TS3<int> {};
  40. // Typedef
  41. typedef int Integer;
  42. //===----------------------------------------------------------------------===//
  43. #elif not defined(HEADER2)
  44. #define HEADER2
  45. #if !defined(HEADER1)
  46. #error Header inclusion order messed up
  47. #endif
  48. //===----------------------------------------------------------------------===//
  49. // Dependent header for C++ chained PCH test
  50. // Overload function from primary
  51. void f(int);
  52. // Add function with different name
  53. void f2();
  54. // Reopen namespace
  55. namespace ns {
  56. // Overload function from primary
  57. void g(int);
  58. // Add different name
  59. void g2();
  60. }
  61. // Specialize template from primary
  62. template <>
  63. struct S<int> { typedef int I; };
  64. // Partially specialize
  65. template <typename T>
  66. struct S<T &> { typedef int J; };
  67. // Specialize previous partial specialization
  68. template <>
  69. struct S<int *> { typedef int K; };
  70. // Specialize the partial specialization from this file
  71. template <>
  72. struct S<int &> { typedef int L; };
  73. template <typename T> struct TS2 { };
  74. struct TestBaseSpecifiers3 { };
  75. struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
  76. struct A { };
  77. struct B : A { };
  78. // Instantiate TS3's members.
  79. static const int ts3m1 = TS3<int>::value;
  80. extern int arr[TS3<int>::value2];
  81. // Redefinition of typedef
  82. typedef int Integer;
  83. //===----------------------------------------------------------------------===//
  84. #else
  85. //===----------------------------------------------------------------------===//
  86. void test() {
  87. f();
  88. f(1);
  89. pf();
  90. f2();
  91. ns::g();
  92. ns::g(1);
  93. ns::pg();
  94. ns::g2();
  95. typedef S<double>::G T1;
  96. typedef S<double *>::H T2;
  97. typedef S<int>::I T3;
  98. typedef S<double &>::J T4;
  99. typedef S<int *>::K T5;
  100. typedef S<int &>::L T6;
  101. TS2int ts2;
  102. B b;
  103. Integer i = 17;
  104. }
  105. // Should have remembered that there is a definition.
  106. static const int ts3m2 = TS3<int>::value;
  107. int arr[TS3<int>::value2];
  108. //===----------------------------------------------------------------------===//
  109. #endif