Skip to content

Commit 6fcfc03

Browse files
committed
Add incomplete type and vla tests
1 parent 2766c87 commit 6fcfc03

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

clang/test/SemaCXX/cxx2c-expansion-stmts.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -fdeclspec -fblocks -verify
1+
// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -fdeclspec -fblocks -Wno-vla-cxx-extension -verify
22
namespace std {
33
template <typename T>
44
struct initializer_list {
@@ -470,7 +470,7 @@ void overload_set(int); // expected-note 2 {{possible target for call}}
470470
void overload_set(long); // expected-note 2 {{possible target for call}}
471471

472472
void invalid_types() {
473-
template for (auto x : void()) {} // expected-error {{cannot expand expression of type 'void'}}
473+
template for (auto x : void()) {} // expected-error {{cannot expand expression of incomplete type 'void'}}
474474
template for (auto x : 1) {} // expected-error {{cannot expand expression of type 'int'}}
475475
template for (auto x : 1.f) {} // expected-error {{cannot expand expression of type 'float'}}
476476
template for (auto x : 'c') {} // expected-error {{cannot expand expression of type 'char'}}
@@ -1040,3 +1040,43 @@ void init_list_bad() {
10401040
template for (auto y : {{1}, {2}, {3, {4}}, {{{5}}}}); // expected-error {{cannot deduce actual type for variable 'y' with type 'auto' from initializer list}} \
10411041
expected-note {{in instantiation of expansion statement requested here}}
10421042
}
1043+
1044+
// Test that the init statement is evaluated even if the expansion statement
1045+
// expands to nothing.
1046+
constexpr int init_stmt_empty_expansion() {
1047+
static constexpr String empty{""};
1048+
int x = 0;
1049+
template for (int _ = x += 1; auto i : {}) {}
1050+
template for (int _ = x += 2; auto i : empty) {}
1051+
template for (int _ = x += 3; auto i : Empty()) {}
1052+
return x;
1053+
}
1054+
1055+
static_assert(init_stmt_empty_expansion() == 6);
1056+
1057+
void vla(int n) {
1058+
int a[n];
1059+
template for (int x : a) {} // expected-error {{cannot expand variable length array type 'int[n]'}}
1060+
}
1061+
1062+
template <typename T>
1063+
void template_vla(T& a) { // expected-note {{variably modified type 'int[n]' cannot be used as a template argument}}
1064+
template for (int x : a) {}
1065+
}
1066+
1067+
void instantiate_template_vla(int n) {
1068+
int a[n];
1069+
template_vla(a); // expected-error {{no matching function for call to 'template_vla'}}
1070+
}
1071+
1072+
struct Incomplete; // expected-note 2 {{forward declaration of 'Incomplete'}}
1073+
void incomplete_type(Incomplete& s) {
1074+
template for (int x : s) {} // expected-error {{cannot expand expression of incomplete type 'Incomplete'}}
1075+
}
1076+
1077+
template <typename T>
1078+
void dependent_incomplete_type(T& s) {
1079+
template for (int x : s) {} // expected-error {{cannot expand expression of incomplete type 'Incomplete'}}
1080+
}
1081+
1082+
template void dependent_incomplete_type<Incomplete>(Incomplete&); // expected-note {{in instantiation of function template specialization 'dependent_incomplete_type<Incomplete>' requested here}}

0 commit comments

Comments
 (0)