Skip to content

Commit d2639ff

Browse files
committed
[NFC] [C++20] [Modules] Add test for #pragma once
Close #38554 Close #58532 It looks like we can workaround the '#pragma once' problem automatically after we force the lazily loading for named modules. Add a test to show this.
1 parent 333ae0a commit d2639ff

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

clang/test/Modules/pr38554.cppm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/c.cppm
6+
7+
//--- a.hpp
8+
#pragma once
9+
using a = int;
10+
11+
//--- b.hpp
12+
#pragma once
13+
#include "a.hpp"
14+
a b;
15+
16+
//--- c.cppm
17+
// expected-no-diagnostics
18+
module;
19+
#include "b.hpp"
20+
export module c;
21+
export using ::a;

clang/test/Modules/pr58532.cppm

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/interface.cppm -emit-module-interface \
6+
// RUN: -o %t/m.pcm
7+
// RUN: %clang_cc1 -std=c++20 %t/implementation.cpp -fmodule-file=m=%t/m.pcm \
8+
// RUN: -fsyntax-only -verify
9+
10+
//--- invisible.h
11+
#pragma once // This breaks things.
12+
const int kInvisibleSymbol = 0;
13+
struct invisible_struct
14+
{};
15+
#define INVISIBLE_DEFINE
16+
17+
//--- visible.h
18+
#include "invisible.h"
19+
const int kSadlyUndeclaredSymbol = kInvisibleSymbol;
20+
using unfortunately_still_invisible_struct = invisible_struct;
21+
#ifndef INVISIBLE_DEFINE
22+
# error "Still not defined."
23+
#endif
24+
25+
//--- interface.cppm
26+
module;
27+
#include "visible.h"
28+
export module m;
29+
30+
//--- implementation.cpp
31+
// expected-no-diagnostics
32+
module;
33+
#include "visible.h"
34+
module m;

0 commit comments

Comments
 (0)