annotate gcc/testsuite/c-c++-common/Wshift-negative-value-3.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* PR c/65179 */
kono
parents:
diff changeset
2 /* { dg-do compile } */
kono
parents:
diff changeset
3 /* { dg-options "-O -Wextra -Wno-shift-negative-value" } */
kono
parents:
diff changeset
4 /* { dg-additional-options "-std=c++11" { target c++ } } */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 enum E {
kono
parents:
diff changeset
7 A = 0 << 1,
kono
parents:
diff changeset
8 B = 1 << 1,
kono
parents:
diff changeset
9 C = -1 << 1,
kono
parents:
diff changeset
10 /* { dg-error "not an integer constant" "no constant" { target c++ } .-1 } */
kono
parents:
diff changeset
11 /* { dg-error "left operand of shift expression" "shift" { target c++ } .-2 } */
kono
parents:
diff changeset
12 D = 0 >> 1,
kono
parents:
diff changeset
13 E = 1 >> 1,
kono
parents:
diff changeset
14 F = -1 >> 1
kono
parents:
diff changeset
15 };
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 int
kono
parents:
diff changeset
18 left (int x)
kono
parents:
diff changeset
19 {
kono
parents:
diff changeset
20 /* Warn for LSHIFT_EXPR. */
kono
parents:
diff changeset
21 const int z = 0;
kono
parents:
diff changeset
22 const int o = 1;
kono
parents:
diff changeset
23 const int m = -1;
kono
parents:
diff changeset
24 int r = 0;
kono
parents:
diff changeset
25 r += z << x;
kono
parents:
diff changeset
26 r += o << x;
kono
parents:
diff changeset
27 r += m << x; /* { dg-bogus "left shift of negative value" } */
kono
parents:
diff changeset
28 r += 0 << x;
kono
parents:
diff changeset
29 r += 1 << x;
kono
parents:
diff changeset
30 r += -1 << x; /* { dg-bogus "left shift of negative value" } */
kono
parents:
diff changeset
31 r += -1U << x;
kono
parents:
diff changeset
32 return r;
kono
parents:
diff changeset
33 }
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 int
kono
parents:
diff changeset
36 right (int x)
kono
parents:
diff changeset
37 {
kono
parents:
diff changeset
38 /* Shouldn't warn for RSHIFT_EXPR. */
kono
parents:
diff changeset
39 const int z = 0;
kono
parents:
diff changeset
40 const int o = 1;
kono
parents:
diff changeset
41 const int m = -1;
kono
parents:
diff changeset
42 int r = 0;
kono
parents:
diff changeset
43 r += z >> x;
kono
parents:
diff changeset
44 r += o >> x;
kono
parents:
diff changeset
45 r += m >> x;
kono
parents:
diff changeset
46 r += 0 >> x;
kono
parents:
diff changeset
47 r += 1 >> x;
kono
parents:
diff changeset
48 r += -1 >> x;
kono
parents:
diff changeset
49 r += -1U >> x;
kono
parents:
diff changeset
50 return r;
kono
parents:
diff changeset
51 }