xref: /llvm-project/clang/test/Headers/crash-instantiated-in-scope-cxx-modules5.cpp (revision cad6bbade0d7dc57b9c43d9ed8c38260345d50bf)
1 // RUN: rm -fR %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
4 // RUN: %clang_cc1 -verify -std=c++20 -Werror=uninitialized -xc++ -emit-module module.cppmap -fmodule-name=mock_resolver -o mock_resolver.pcm
5 // RUN: %clang_cc1 -verify -std=c++20 -Werror=uninitialized -xc++ -emit-module module.cppmap -fmodule-name=sql_internal -o sql_internal.pcm
6 // RUN: %clang_cc1 -verify -std=c++20 -Werror=uninitialized -xc++ -fmodule-file=mock_resolver.pcm -fmodule-file=sql_internal.pcm main.cc -o main.o
7 
8 //--- module.cppmap
9 module "mock_resolver" {
10   export *
11   module "mock_resolver.h" {
12     export *
13     header "mock_resolver.h"
14   }
15 }
16 
17 module "sql_internal" {
18   export *
19   module "sql_transform_builder.h" {
20     export *
21     header "sql_transform_builder.h"
22   }
23 }
24 
25 //--- set_bits2.h
26 // expected-no-diagnostics
27 #pragma once
28 
29 template <typename T>
30 void fwd(const T& x) {}
31 
32 namespace vox::bitset {
33 
34 template <typename TFunc>
35 void ForEachSetBit2(const TFunc&) {
36   fwd([](int) {
37     const int bit_index_base = 0;
38     (void)[&](int) {
39       int v = bit_index_base;
40     };
41   });
42 }
43 
44 }  // namespace vox::bitset
45 
46 //--- sql_transform_builder.h
47 // expected-no-diagnostics
48 #pragma once
49 
50 #include "set_bits2.h"
51 
52 class QualifyingSet3 {
53  public:
54   void GetIndexes() const {
55     vox::bitset::ForEachSetBit2([]() {});
56   }
57 };
58 
59 template <typename T>
60 void DoTransform() {
61   vox::bitset::ForEachSetBit2([]() {});
62 }
63 
64 //--- mock_resolver.h
65 // expected-no-diagnostics
66 #pragma once
67 #include "set_bits2.h"
68 
69 class QualifyingSet2 {
70  public:
71   void GetIndexes() const {
72     vox::bitset::ForEachSetBit2([]() {});
73   }
74 };
75 
76 //--- main.cc
77 // expected-no-diagnostics
78 #include "sql_transform_builder.h"
79 
80 template <typename Callable>
81 void get(const Callable& fn) {
82   fwd<Callable>(fn);
83 }
84 
85 namespace {
86 
87 void test() {
88   get([]() {});
89   DoTransform<int>();
90 }
91 
92 } // namespace
93