Debian Codegraph @

gcc/testsuite/g++.dg/ubsan/pr70135.C

raw
1 // PR c++/70135
2 // { dg-do run }
3 // { dg-options "-fsanitize=bounds -std=c++14" }
4
5 template <bool... b>
6 struct S {
7 static constexpr bool c[] {b...};
8 static constexpr auto foo ()
9 {
10 unsigned long n = 0;
11 for (unsigned long i = 0; i < sizeof (c); i++)
12 if (!c[i])
13 ++n;
14 return n;
15 }
16 static constexpr auto n = foo () + 1;
17 static constexpr auto bar ()
18 {
19 int h = 0;
20 for (int g = 0, i = 0; g < n; ++g)
21 {
22 while (i < sizeof...(b) && c[i++])
23 ++h;
24 h += 64;
25 }
26 return h;
27 }
28 };
29
30 int
31 main ()
32 {
33 S <true, false, false, true, true, true, false, true> s;
34 constexpr auto c = s.bar ();
35 static_assert (s.bar () == 4 * 64 + 5, "");
36 }