| 1 |
// RUN: mkdir -p %t |
| 2 |
// RUN: split-file %s %t |
| 3 |
|
| 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 -verify |
| 6 |
// 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: -fdeclspec |
| 9 |
|
| 10 |
//--- bad-header-unit.h |
| 11 |
|
| 12 |
inline int ok_foo () { return 0;} |
| 13 |
|
| 14 |
static int ok_bar (); |
| 15 |
|
| 16 |
int ok_decl (); |
| 17 |
|
| 18 |
int bad_def () { return 2;} // expected-error {{non-inline external definitions are not permitted in C++ header units}} |
| 19 |
|
| 20 |
inline int ok_inline_var = 1; |
| 21 |
|
| 22 |
static int ok_static_var; |
| 23 |
|
| 24 |
int ok_var_decl; |
| 25 |
|
| 26 |
int 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 |
|
| 30 |
class A { |
| 31 |
public: |
| 32 |
// This is a declaration instead of definition. |
| 33 |
static const int value = 43; |
| 34 |
}; |
| 35 |
|
| 36 |
void deleted_fn_ok (void) = delete; |
| 37 |
|
| 38 |
struct S { |
| 39 |
~S() noexcept(false) = default; |
| 40 |
private: |
| 41 |
S(S&); |
| 42 |
}; |
| 43 |
S::S(S&) = default; |
| 44 |
|
| 45 |
template <class _X> |
| 46 |
_X tmpl_var_ok_0 = static_cast<_X>(-1); |
| 47 |
|
| 48 |
template <typename _T> |
| 49 |
constexpr _T tmpl_var_ok_1 = static_cast<_T>(42); |
| 50 |
|
| 51 |
inline int a = tmpl_var_ok_1<int>; |
| 52 |
|
| 53 |
template <typename _Tp, |
| 54 |
template <typename> class _T> |
| 55 |
constexpr int tmpl_var_ok_2 = _T<_Tp>::value ? 42 : 6174 ; |
| 56 |
|
| 57 |
template<class _Ep> |
| 58 |
int tmpl_OK (_Ep) { return 0; } |
| 59 |
|
| 60 |
template <class _T1> |
| 61 |
bool |
| 62 |
operator==(_T1& , _T1& ) { return false; } |
| 63 |
|
| 64 |
constexpr long one_k = 1000L; |
| 65 |
|
| 66 |
template <class ..._Args> |
| 67 |
void* tmpl_fn_ok |
| 68 |
(_Args ...__args) { return nullptr; } |
| 69 |
|
| 70 |
inline int foo (int a) { |
| 71 |
return tmpl_OK (a); |
| 72 |
} |
| 73 |
|
| 74 |
template <typename T> struct S2 { static int v; }; |
| 75 |
template <typename T> int S2<T>::v = 10; |
| 76 |
|
| 77 |
template <typename T> bool b() { |
| 78 |
bool b1 = S2<T>::v == 10; |
| 79 |
return b1 && true; |
| 80 |
} |
| 81 |
|
| 82 |
inline 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.h |
| 89 |
|
| 90 |
/* The cases below should compile without diagnostics. */ |
| 91 |
|
| 92 |
__declspec(selectany) int selectany_var_definition = 42; // expected-no-diagnostics |