|
| 1 | +// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -fexpansion-limit=32 -verify |
| 2 | + |
| 3 | +void g(int); |
| 4 | + |
| 5 | +template <__SIZE_TYPE__ size> |
| 6 | +struct String { |
| 7 | + char data[size]; |
| 8 | + |
| 9 | + template <__SIZE_TYPE__ n> |
| 10 | + constexpr String(const char (&str)[n]) { __builtin_memcpy(data, str, n); } |
| 11 | + |
| 12 | + constexpr const char* begin() const { return data; } |
| 13 | + constexpr const char* end() const { return data + size - 1; } |
| 14 | +}; |
| 15 | + |
| 16 | +template <__SIZE_TYPE__ n> |
| 17 | +String(const char (&str)[n]) -> String<n>; |
| 18 | + |
| 19 | +template <typename T, __SIZE_TYPE__ size> |
| 20 | +struct Array { |
| 21 | + T data[size]{}; |
| 22 | + constexpr const T* begin() const { return data; } |
| 23 | + constexpr const T* end() const { return data + size; } |
| 24 | +}; |
| 25 | + |
| 26 | +void expansion_size() { |
| 27 | + static constexpr Array<int, 32> almost_too_big; |
| 28 | + template for (auto x : almost_too_big) g(x); |
| 29 | + template for (constexpr auto x : almost_too_big) g(x); |
| 30 | + |
| 31 | + static constexpr Array<int, 33> too_big; |
| 32 | + template for (auto x : too_big) g(x); // expected-error {{expansion size 33 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 33 | + template for (constexpr auto x : too_big) g(x); // expected-error {{expansion size 33 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 34 | + |
| 35 | + static constexpr String big{"1234567890123456789012345678901234567890234567890"}; |
| 36 | + template for (auto x : big) g(x); // expected-error {{expansion size 49 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 37 | + template for (constexpr auto x : big) g(x); // expected-error {{expansion size 49 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 38 | + |
| 39 | + template for (auto x : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
| 40 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 41 | + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
| 42 | + 31, 32}) g(x); |
| 43 | + template for (constexpr auto x : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
| 44 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 45 | + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
| 46 | + 31, 32}) g(x); |
| 47 | + |
| 48 | + template for (auto x : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // expected-error {{expansion size 33 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 49 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 50 | + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
| 51 | + 31, 32, 33}) g(x); |
| 52 | + template for (constexpr auto x : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // expected-error {{expansion size 33 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 53 | + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 54 | + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
| 55 | + 31, 32, 33}) g(x); |
| 56 | + |
| 57 | + int huge[1'000'000'000]; |
| 58 | + template for (auto x : huge) {} // expected-error {{expansion size 1000000000 exceeds maximum configured size 32}} expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 59 | +} |
| 60 | + |
| 61 | +void array_too_big() { |
| 62 | + int ok[32]; |
| 63 | + int too_big[33]; |
| 64 | + |
| 65 | + template for (auto x : ok) {} |
| 66 | + template for (auto x : too_big) {} // expected-error {{expansion size 33 exceeds maximum configured size 32}} \ |
| 67 | + expected-note {{use -fexpansion-limit=N to adjust this limit}} |
| 68 | +} |
0 commit comments