Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions clang/test/CXX/basic/basic.link/p3.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
// RUN: %clang_cc1 -std=c++2a -verify %s
// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=1
// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=2
// RUN: rm -rf %t
// RUN: split-file %s %t

// RUN: %clang_cc1 -std=c++20 -verify %t/M.cpp
// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError1.cpp
// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError2.cpp

//--- M.cpp
module;

#if IMPORT_ERROR != 2
struct import { struct inner {}; };
#endif
struct module { struct inner {}; };

constexpr int n = 123;

export module m; // #1

// Import errors are fatal, so we test them in isolation.
#if IMPORT_ERROR == 1
import x = {}; // expected-error {{expected ';' after module name}}
// expected-error@-1 {{module 'x' not found}}

#elif IMPORT_ERROR == 2
struct X;
template<int> struct import;
template<> struct import<n> {
static X y;
};

// This is not valid because the 'import <n>' is a pp-import, even though it
// grammatically can't possibly be an import declaration.
struct X {} import<n>::y; // expected-error {{'n' file not found}}

#else
module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}}
// expected-note@#1 {{previous module declaration}}

Expand All @@ -51,4 +34,36 @@ template<typename T> module module_var_template;

// This is a variable named 'import' that shadows the type 'import' above.
struct X {} import;
#endif

//--- ImportError1.cpp
module;

struct import { struct inner {}; };
struct module { struct inner {}; };

constexpr int n = 123;

export module m; // #1

import x = {}; // expected-error {{expected ';' after module name}}
// expected-error@-1 {{module 'x' not found}}

//--- ImportError2.cpp
module;

struct module { struct inner {}; };

constexpr int n = 123;

export module m; // #1

struct X;
template<int> struct import;
template<> struct import<n> {
static X y;
};

// This is not valid because the 'import <n>' is a pp-import, even though it
// grammatically can't possibly be an import declaration.
struct X {} import<n>::y; // expected-error {{'n' file not found}}