| 1 |
// PR c++/89074 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
int fn1 (void) { return 0; } |
| 5 |
int fn2 (void) { return 1; } |
| 6 |
|
| 7 |
constexpr bool |
| 8 |
f1 () |
| 9 |
{ |
| 10 |
char a[] = { 1, 2, 3, 4 }; |
| 11 |
|
| 12 |
if (&a[1] == "foo") |
| 13 |
return false; |
| 14 |
|
| 15 |
if (&a[1] == &"foo"[4]) |
| 16 |
return false; |
| 17 |
|
| 18 |
if (&"foo"[1] == &a[0]) |
| 19 |
return false; |
| 20 |
|
| 21 |
if (&"foo"[3] == &a[4]) |
| 22 |
return false; |
| 23 |
|
| 24 |
if (&a[0] == "foo") |
| 25 |
return false; |
| 26 |
|
| 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; |
| 30 |
|
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
constexpr bool |
| 35 |
f2 () |
| 36 |
{ |
| 37 |
char a[] = { 1, 2, 3, 4 }; |
| 38 |
|
| 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; |
| 42 |
|
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
char v[] = { 1, 2, 3, 4 }; |
| 47 |
|
| 48 |
constexpr bool |
| 49 |
f3 () |
| 50 |
{ |
| 51 |
char a[] = { 1, 2, 3, 4 }; |
| 52 |
|
| 53 |
if (&a[1] == &v[1]) |
| 54 |
return false; |
| 55 |
|
| 56 |
if (&a[0] == &v[3]) |
| 57 |
return false; |
| 58 |
|
| 59 |
if (&a[2] == &v[4]) |
| 60 |
return false; |
| 61 |
|
| 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; |
| 65 |
|
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
constexpr bool |
| 70 |
f4 () |
| 71 |
{ |
| 72 |
char a[] = { 1, 2, 3, 4, 5 }; |
| 73 |
|
| 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; |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
constexpr bool |
| 82 |
f5 () |
| 83 |
{ |
| 84 |
if (fn1 != fn1) |
| 85 |
return false; |
| 86 |
|
| 87 |
if (fn1 == fn2) |
| 88 |
return false; |
| 89 |
|
| 90 |
if (&"abcde"[0] == &"edcba"[1]) |
| 91 |
return false; |
| 92 |
|
| 93 |
if (&"abcde"[1] == &"edcba"[6]) |
| 94 |
return false; |
| 95 |
|
| 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; |
| 99 |
|
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
constexpr bool |
| 104 |
f6 () |
| 105 |
{ |
| 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; |
| 109 |
|
| 110 |
return true; |
| 111 |
} |
| 112 |
|
| 113 |
constexpr bool |
| 114 |
f7 () |
| 115 |
{ |
| 116 |
if (&"abcde"[3] == &"fabcde"[3]) |
| 117 |
return false; |
| 118 |
|
| 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; |
| 122 |
|
| 123 |
return true; |
| 124 |
} |
| 125 |
|
| 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 (); |