comparison gcc/testsuite/c-c++-common/array-5.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* PR c++/87996 - "size of array is negative" error when SIZE_MAX/2 < sizeof(array) <= SIZE_MAX
2 { dg-do compile }
3 { dg-options "-ftrack-macro-expansion=0" } */
4
5 #define INT16_MAX __INT16_MAX__
6 #define UINT16_MAX ((INT16_MAX << 1) + 1)
7
8 #define DIFF_MAX __PTRDIFF_MAX__
9 #define SIZE_MAX __SIZE_MAX__
10
11 typedef __INT16_TYPE__ int16_t;
12 typedef __INT32_TYPE__ int32_t;
13 typedef __SIZE_TYPE__ size_t;
14
15 /* Verify errors for types. */
16
17 typedef char i8a1_d_m1_t[DIFF_MAX - 1];
18 /* The following should also be diagnosed because the difference between
19 &i8a1_dx[0] and &i8a1_dx[sizeof i8a1_dx] cannot be represented.
20 typedef char i8a1_d_t[DIFF_MAX];
21 */
22
23 typedef char i8a1_d_p1_t[(size_t)DIFF_MAX + 1]; /* { dg-error "size .\[0-9\]+. of array .i8a1_d_p1_t. exceeds maximum object size .\[0-9\]+.|is too large" } */
24
25 typedef char i8a1_s_t[SIZE_MAX]; /* { dg-error "size .\[0-9\]+. of array .i8a1_s_t. exceeds maximum object size .\[0-9\]+.|is too large" } */
26
27 typedef int16_t i16a_s_d2_t[SIZE_MAX / 2]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d2_t. exceeds maximum object size .\[0-9\]+." } */
28 typedef int16_t i16a_s_d3_t[SIZE_MAX / 3]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d3_t. exceeds maximum object size .\[0-9\]+." } */
29 typedef int16_t i16a_s_d4_m1_t[SIZE_MAX / 4 - 1];
30 typedef int16_t i16a_s_d4_p1_t[SIZE_MAX / 4 + 1]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d4_p1_t. exceeds maximum object size .\[0-9\]+." } */
31
32 /* The internal computation overflows the message doesn't show the object
33 size (but GCC should compute the result and print it anyway). */
34 typedef int32_t i32a_s_d2_t[SIZE_MAX / 2]; /* { dg-error "size of array .i32a_s_d2_t. exceeds maximum object size .\[0-9\]+." } */
35 typedef int32_t i32a_s_d3_t[SIZE_MAX / 3]; /* { dg-error "size of array .i32a_s_d3_t. exceeds maximum object size .\[0-9\]+." } */
36 typedef int32_t i32a_s_d4_t[SIZE_MAX / 4]; /* { dg-error "size .\[0-9\]+. of array .i32a_s_d4_t. exceeds maximum object size .\[0-9\]+." } */
37
38
39 /* Verify errors for objects. */
40
41 char i8a1_d_m1[DIFF_MAX - 1];
42 /* The following should also be diagnosed because the difference between
43 &i8a1_dx[0] and &i8a1_dx[sizeof i8a1_dx] cannot be represented.
44 char i8a1_d[DIFF_MAX];
45 */
46
47 char i8a_d_p1[(size_t)DIFF_MAX + 1]; /* { dg-error "size .\[0-9\]+. of array .i8a_d_p1. exceeds maximum object size .\[0-9\]+.|is too large" } */
48
49 char i8a_s[SIZE_MAX]; /* { dg-error "size .\[0-9\]+. of array .i8a_s. exceeds maximum object size .\[0-9\]+.|is too large" } */
50
51 int16_t i16a_s_d2[SIZE_MAX / 2]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d2. exceeds maximum object size .\[0-9\]+." } */
52 int16_t i16a_s_d3[SIZE_MAX / 3]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d3. exceeds maximum object size .\[0-9\]+." } */
53 int16_t i16a_sz_d4_m1[SIZE_MAX / 4 - 1];
54 int16_t i16a_sz_d4_p1[SIZE_MAX / 4 + 1]; /* { dg-error "size .\[0-9\]+. of array .i16a_sz_d4_p1. exceeds maximum object size .\[0-9\]+." } */
55
56 /* The internal computation overflows the message doesn't show the object
57 size (but GCC should compute the result and print it anyway). */
58 int32_t i32a_s_d2[SIZE_MAX / 2]; /* { dg-error "size of array .i32a_s_d2. exceeds maximum object size .\[0-9\]+." } */
59 int32_t i32a_s_d3[SIZE_MAX / 3]; /* { dg-error "size of array .i32a_s_d3. exceeds maximum object size .\[0-9\]+." } */
60 int32_t i32a_s_d4[SIZE_MAX / 4]; /* { dg-error "size .\[0-9\]+. of array .i32a_s_d4. exceeds maximum object size .\[0-9\]+." } */