Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/init-statement6.C

raw
1 // Testcase from P0305R1
2 // { dg-do compile { target c++17 } }
3 // { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } }
4
5 #include <string>
6 #include <map>
7 #include <algorithm>
8
9 std::map<int, std::string> m;
10 extern int xread (int *);
11 extern void publish (int), xraise (int);
12
13 void
14 foo ()
15 {
16 if (auto it = m.find (10); it != m.end ()) { std::string s = it->second; }
17 if (char buf[10]; std::fgets(buf, 10, stdin)) { m[0] += buf; }
18 if (int s; int count = xread (&s)) { publish(count); xraise(s); }
19
20 const char *s;
21 if (auto keywords = {"if", "for", "while"};
22 std::any_of(keywords.begin(), keywords.end(), [&s](const char* kw) { return s == kw; }))
23 {
24 // whatever
25 }
26 }