gcc/testsuite/g++.dg/cpp23/attr-assume10.C
raw| 1 | // Test that s.i is not modified by the assume. |
| 2 | // { dg-do compile { target c++17 } } |
| 3 | |
| 4 | struct string |
| 5 | { |
| 6 | const char *p; |
| 7 | int i; |
| 8 | constexpr string (const char *p): p(p), i(0) { } |
| 9 | constexpr int length () { ++i; return __builtin_strlen (p); } |
| 10 | }; |
| 11 | |
| 12 | constexpr int f() |
| 13 | { |
| 14 | string s ("foobar"); |
| 15 | [[assume (s.length () > 0)]]; |
| 16 | if (s.i != 0) __builtin_abort(); |
| 17 | int len = s.length (); |
| 18 | if (s.i != 1) __builtin_abort(); |
| 19 | return len; |
| 20 | } |
| 21 | |
| 22 | static_assert (f()); |