@@ -33,6 +33,30 @@ extern "C" {
33
33
extern wchar_t *wmemcpy (wchar_t *d, const wchar_t *s, size_t n);
34
34
}
35
35
36
+
37
+ constexpr int test_address_of_incomplete_array_type () { // both-error {{never produces a constant expression}}
38
+ extern int arr[];
39
+ __builtin_memmove (&arr, &arr, 4 * sizeof (arr[0 ])); // both-note 2{{cannot constant evaluate 'memmove' between objects of incomplete type 'int[]'}}
40
+ return arr[0 ] * 1000 + arr[1 ] * 100 + arr[2 ] * 10 + arr[3 ];
41
+ }
42
+ static_assert (test_address_of_incomplete_array_type() == 1234, ""); // both-error {{constant}} \
43
+ // both-note {{in call}}
44
+
45
+
46
+ struct NonTrivial {
47
+ constexpr NonTrivial () : n(0 ) {}
48
+ constexpr NonTrivial (const NonTrivial &) : n(1 ) {}
49
+ int n;
50
+ };
51
+ constexpr bool test_nontrivial_memcpy () { // ref-error {{never produces a constant}}
52
+ NonTrivial arr[3 ] = {};
53
+ __builtin_memcpy (arr, arr + 1 , sizeof (NonTrivial)); // both-note {{non-trivially-copyable}} \
54
+ // ref-note {{non-trivially-copyable}}
55
+ return true ;
56
+ }
57
+ static_assert (test_nontrivial_memcpy()); // both-error {{constant}} \
58
+ // both-note {{in call}}
59
+
36
60
namespace strcmp {
37
61
constexpr char kFoobar [6 ] = {' f' ,' o' ,' o' ,' b' ,' a' ,' r' };
38
62
constexpr char kFoobazfoobar [12 ] = {' f' ,' o' ,' o' ,' b' ,' a' ,' z' ,' f' ,' o' ,' o' ,' b' ,' a' ,' r' };
@@ -1349,6 +1373,17 @@ namespace BuiltinMemcpy {
1349
1373
// both-note {{source of 'memcpy' is (void *)123}}
1350
1374
static_assert (__builtin_memcpy(fold(reinterpret_cast <wchar_t *>(123 )), &global, sizeof (wchar_t ))); // both-error {{not an integral constant expression}} \
1351
1375
// both-note {{destination of 'memcpy' is (void *)123}}
1376
+
1377
+
1378
+ constexpr float type_pun (const unsigned &n) {
1379
+ float f = 0 .0f ;
1380
+ __builtin_memcpy (&f, &n, 4 ); // both-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
1381
+ return f;
1382
+ }
1383
+ static_assert (type_pun(0x3f800000 ) == 1 .0f ); // both-error {{constant}} \
1384
+ // both-note {{in call}}
1385
+
1386
+
1352
1387
}
1353
1388
1354
1389
namespace Memcmp {
0 commit comments