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