93 lines · cpp
1// RUN: mkdir -p %t2// RUN: split-file %s %t3 4// RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit.h \5// RUN: -emit-header-unit -o %t/bad-header-unit.pcm -verify6// RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit-declspec.h \7// RUN: -emit-header-unit -o %t/bad-header-unit.pcm -verify \8// RUN: -fdeclspec9 10//--- bad-header-unit.h11 12inline int ok_foo () { return 0;}13 14static int ok_bar ();15 16int ok_decl ();17 18int bad_def () { return 2;} // expected-error {{non-inline external definitions are not permitted in C++ header units}}19 20inline int ok_inline_var = 1;21 22static int ok_static_var;23 24int ok_var_decl;25 26int bad_var_definition = 3; // expected-error {{non-inline external definitions are not permitted in C++ header units}}27 28/* The cases below should compile without diagnostics. */29 30class A {31public:32 // This is a declaration instead of definition.33 static const int value = 43; 34};35 36void deleted_fn_ok (void) = delete;37 38struct S {39 ~S() noexcept(false) = default;40private:41 S(S&);42};43S::S(S&) = default;44 45template <class _X>46_X tmpl_var_ok_0 = static_cast<_X>(-1);47 48template <typename _T>49constexpr _T tmpl_var_ok_1 = static_cast<_T>(42);50 51inline int a = tmpl_var_ok_1<int>;52 53template <typename _Tp,54 template <typename> class _T>55constexpr int tmpl_var_ok_2 = _T<_Tp>::value ? 42 : 6174 ;56 57template<class _Ep>58int tmpl_OK (_Ep) { return 0; }59 60template <class _T1>61bool62operator==(_T1& , _T1& ) { return false; }63 64constexpr long one_k = 1000L;65 66template <class ..._Args>67void* tmpl_fn_ok68(_Args ...__args) { return nullptr; }69 70inline int foo (int a) {71 return tmpl_OK (a);72}73 74template <typename T> struct S2 { static int v; };75template <typename T> int S2<T>::v = 10;76 77template <typename T> bool b() {78 bool b1 = S2<T>::v == 10;79 return b1 && true;80}81 82inline bool B = b<int>();83 84__attribute__((weak)) int weak_fun_definition() { return 42; }85 86__attribute__((weak)) int weak_var_definition = 42;87 88//--- bad-header-unit-declspec.h89 90/* The cases below should compile without diagnostics. */91 92__declspec(selectany) int selectany_var_definition = 42; // expected-no-diagnostics93