xref: /llvm-project/clang/test/Modules/pr60775.cppm (revision 482c41e992c1edf8833a4577b56ff9dda49fbc83)
1// https://github.com/llvm/llvm-project/issues/60775
2//
3// RUN: rm -rf %t
4// RUN: mkdir -p %t
5// RUN: split-file %s %t
6//
7// RUN: %clang_cc1 -std=c++20 %t/a.cppm -I%t -emit-module-interface -o %t/a.pcm
8// RUN: %clang_cc1 -std=c++20 %t/b.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
9// RUN: %clang_cc1 -std=c++20 %t/c.cppm -I%t -emit-module-interface -o %t/c.pcm
10// RUN: %clang_cc1 -std=c++20 %t/d.cppm -emit-module-interface -fmodule-file=c=%t/c.pcm -o %t/d.pcm
11// RUN: %clang_cc1 -std=c++20 %t/e.cpp -fmodule-file=d=%t/d.pcm -fmodule-file=c=%t/c.pcm -verify -fsyntax-only
12// RUN: %clang_cc1 -std=c++20 %t/f.cppm -emit-module-interface -fmodule-file=c=%t/c.pcm -o %t/f.pcm
13// RUN: %clang_cc1 -std=c++20 %t/g.cpp -fmodule-file=f=%t/f.pcm -fmodule-file=c=%t/c.pcm  -verify -fsyntax-only
14
15// Test again with reduced BMI
16// RUN: rm -rf %t
17// RUN: mkdir -p %t
18// RUN: split-file %s %t
19//
20// RUN: %clang_cc1 -std=c++20 %t/a.cppm -I%t -emit-reduced-module-interface -o %t/a.pcm
21// RUN: %clang_cc1 -std=c++20 %t/b.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
22// RUN: %clang_cc1 -std=c++20 %t/c.cppm -I%t -emit-reduced-module-interface -o %t/c.pcm
23// RUN: %clang_cc1 -std=c++20 %t/d.cppm -emit-reduced-module-interface -fmodule-file=c=%t/c.pcm -o %t/d.pcm
24// RUN: %clang_cc1 -std=c++20 %t/e.cpp -fmodule-file=d=%t/d.pcm -fmodule-file=c=%t/c.pcm -verify -fsyntax-only
25// RUN: %clang_cc1 -std=c++20 %t/f.cppm -emit-reduced-module-interface -fmodule-file=c=%t/c.pcm -o %t/f.pcm
26// RUN: %clang_cc1 -std=c++20 %t/g.cpp -fmodule-file=f=%t/f.pcm -fmodule-file=c=%t/c.pcm  -verify -fsyntax-only
27
28//--- initializer_list.h
29namespace std {
30  typedef decltype(sizeof(int)) size_t;
31  template<typename T> struct initializer_list {
32    const T* ptr; size_t sz;
33    initializer_list(const T *, size_t);
34    const T* begin();
35    const T* end();
36  };
37}
38
39//--- a.cppm
40module;
41#include "initializer_list.h"
42export module a;
43export template<typename>
44void a() {
45	for (int x : {0}) {
46	}
47}
48
49//--- b.cpp
50// expected-no-diagnostics
51import a;
52void b() {
53	a<int>();
54}
55
56//--- c.cppm
57module;
58#include "initializer_list.h"
59export module c;
60namespace std {
61    export using std::initializer_list;
62}
63
64//--- d.cppm
65export module d;
66import c;
67export template<typename>
68void d() {
69	for (int x : {0}) {
70	}
71}
72
73//--- e.cpp
74import d;
75void e() {
76    for (int x : {0}) { // expected-error {{cannot deduce type of initializer list because std::initializer_list was not found; include <initializer_list>}}
77	}
78}
79
80template <typename>
81void ee() {
82    for (int x : {0}) { // expected-error {{cannot deduce type of initializer list because std::initializer_list was not found; include <initializer_list>}}
83    }
84}
85
86void eee() {
87    ee<int>();
88    d<int>();
89}
90
91//--- f.cppm
92export module f;
93export import c;
94
95//--- g.cpp
96// expected-no-diagnostics
97import f;
98void g() {
99    for (int x : {0}) {
100	}
101}
102
103template <typename>
104void gg() {
105    for (int x : {0}) {
106    }
107}
108
109void ggg() {
110    gg<int>();
111}
112