c++: robustify testcase [PR109752]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-89074-3.C
blob91a2e99c38f4a5b41f65abbf853cf86fc68b5f88
1 // PR c++/89074
2 // { dg-do compile { target c++14 } }
4 int fn1 (void) { return 0; }
5 int fn2 (void) { return 1; }
7 constexpr bool
8 f1 ()
10   char a[] = { 1, 2, 3, 4 };
12   if (&a[1] == "foo")
13     return false;
15   if (&a[1] == &"foo"[4])
16     return false;
18   if (&"foo"[1] == &a[0])
19     return false;
21   if (&"foo"[3] == &a[4])
22     return false;
24   if (&a[0] == "foo")
25     return false;
27   // Pointer to start of one object (var) and end of another one (literal)
28   if (&a[0] == &"foo"[4])       // { dg-error "is not a constant expression" }
29     return false;
31   return true;
34 constexpr bool
35 f2 ()
37   char a[] = { 1, 2, 3, 4 };
39   // Pointer to end of one object (var) and start of another one (literal)
40   if (&a[4] == "foo")           // { dg-error "is not a constant expression" }
41     return false;
43   return true;
46 char v[] = { 1, 2, 3, 4 };
48 constexpr bool
49 f3 ()
51   char a[] = { 1, 2, 3, 4 };
53   if (&a[1] == &v[1])
54     return false;
56   if (&a[0] == &v[3])
57     return false;
59   if (&a[2] == &v[4])
60     return false;
62   // Pointer to start of one object (automatic var) and end of another one (non-automagic var)
63   if (&a[0] == &v[4])           // { dg-error "is not a constant expression" }
64     return false;
66   return true;
69 constexpr bool
70 f4 ()
72   char a[] = { 1, 2, 3, 4, 5 };
74   // Pointer to end of one object (automatic var) and start of another one (non-automagic var)
75   if (&a[5] == &v[0])           // { dg-error "is not a constant expression" }
76     return false;
78   return true;
81 constexpr bool
82 f5 ()
84   if (fn1 != fn1)
85     return false;
87   if (fn1 == fn2)
88     return false;
90   if (&"abcde"[0] == &"edcba"[1])
91     return false;
93   if (&"abcde"[1] == &"edcba"[6])
94     return false;
96   // Pointer to start of one object (literal) and end of another one (literal)
97   if (&"abcde"[0] == &"edcba"[6])       // { dg-error "is not a constant expression" }
98     return false;
100   return true;
103 constexpr bool
104 f6 ()
106   // Pointer to start of one object (literal) and end of another one (literal)
107   if (&"abcde"[6] == &"edcba"[0])       // { dg-error "is not a constant expression" }
108     return false;
110   return true;
113 constexpr bool
114 f7 ()
116   if (&"abcde"[3] == &"fabcde"[3])
117     return false;
119   // These could be suffix merged, with &"abcde"[0] == &"fabcde"[1].
120   if (&"abcde"[3] == &"fabcde"[4])      // { dg-error "is not a constant expression" }
121     return false;
123   return true;
126 constexpr bool a = f1 ();
127 constexpr bool b = f2 ();
128 constexpr bool c = f3 ();
129 constexpr bool d = f4 ();
130 constexpr bool e = f5 ();
131 constexpr bool f = f6 ();
132 constexpr bool g = f7 ();