xref: /llvm-project/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp (revision 38b3d87bd384a469a6618ec6a971352cb4f813ba)
1 // RUN: rm -fR %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
4 // RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-name=foo1 -emit-module modules.map -o foo1.pcm
5 // RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-name=foo2 -emit-module modules.map -o foo2.pcm
6 // RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc
7 
8 //--- functional
9 #pragma once
10 
11 namespace std {
12 template <class> class function {};
13 } // namespace std
14 
15 //--- foo.h
16 #pragma once
17 
18 class MethodHandler {
19  public:
20   virtual ~MethodHandler() {}
21   struct HandlerParameter {
22     HandlerParameter();
23   };
24   virtual void RunHandler(const HandlerParameter &param);
25 };
26 
27 template <class RequestType, class ResponseType>
28 class CallbackUnaryHandler : public MethodHandler {
29  public:
30   explicit CallbackUnaryHandler();
31 
32   void RunHandler(const HandlerParameter &param) final {
33     void *call = nullptr;
34     (void)[call](bool){};
35   }
36 };
37 
38 //--- foo1.h
39 // expected-no-diagnostics
40 #pragma once
41 
42 #include "functional"
43 
44 #include "foo.h"
45 
46 class A;
47 
48 class ClientAsyncResponseReaderHelper {
49    public:
50       using t = std::function<void(A)>;
51         static void SetupRequest(t finish);
52 };
53 
54 //--- foo2.h
55 // expected-no-diagnostics
56 #pragma once
57 
58 #include "foo.h"
59 
60 template <class BaseClass>
61 class a : public BaseClass {
62  public:
63   a() { [[maybe_unused]] CallbackUnaryHandler<int, int> a; }
64 };
65 
66 //--- modules.map
67 module "foo" {
68   export *
69   module "foo.h" {
70     export *
71     textual header "foo.h"
72   }
73 }
74 
75 module "foo1" {
76   export *
77   module "foo1.h" {
78     export *
79     header "foo1.h"
80   }
81 
82   use "foo"
83 }
84 
85 module "foo2" {
86   export *
87   module "foo2.h" {
88     export *
89     header "foo2.h"
90   }
91 
92   use "foo"
93 }
94 
95 //--- server.cc
96 // expected-no-diagnostics
97 #include "functional"
98 
99 #include "foo1.h"
100 #include "foo2.h"
101 
102 std::function<void()> on_emit;
103 
104 template <class RequestType, class ResponseType>
105 class CallbackUnaryHandler;
106 
107 class s {};
108 class hs final : public a<s> {
109   explicit hs() {}
110 };
111