aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/attr-assume10.C
blob: 475555ac415ddeb989eadf5701e8df3fc1cc66b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Test that s.i is not modified by the assume.
// { dg-do compile { target c++17 } }

struct string
{
  const char *p;
  int i;
  constexpr string (const char *p): p(p), i(0) { }
  constexpr int length () { ++i; return __builtin_strlen (p); }
};

constexpr int f()
{
  string s ("foobar");
  [[assume (s.length () > 0)]];
  if (s.i != 0) __builtin_abort();
  int len = s.length ();
  if (s.i != 1) __builtin_abort();
  return len;
}

static_assert (f());