else
bar (-p);
}
-// { dg-do compile { target c++11 } }
-// { dg-options "" }
-
-extern int foo (void);
-extern void bar (int);
-
-void
-f (void)
-{
- if (auto p = foo (); p > 10) // { dg-warning "init-statement" "" { target c++14_down } }
- bar (p);
- else
- bar (-p);
-}
if constexpr (constexpr auto s = sizeof (int); s > 10)
foo ();
}
-// { dg-options -std=c++1z }
-// Test C++17 selection statements with initializer, basic use.
-
-extern int foo (void);
-extern void bar (int);
-extern int g;
-
-void
-f (void)
-{
- if (auto p = foo (); p > 10)
- bar (p);
- else
- bar (-p);
-
- if ((g += 2); g > 6)
- bar (1);
-
- if (auto a = 9, b = foo (); a + b > 10)
- bar (a + b);
- else
- bar (a - b);
-
- if (({ int a; 1;}))
- bar (0);
-
- if (auto i = foo (); i > 6)
- bar (0);
- else if (i++; i > 8)
- bar (1);
-}
-
-extern void lock (void);
-
-void
-f2 (int i)
-{
- if (lock (); i > 10)
- ++i;
- else
- --i;
-}
-
-void
-f3 (int i)
-{
- switch (i *= 2; auto idx = i)
- {
- case 4:
- bar (3);
- break;
- default:
- break;
- }
-}
-
-void
-f4 (void)
-{
- if constexpr (constexpr auto s = sizeof (int); s > 10)
- foo ();
-}
if (g != 2)
__builtin_abort ();
}
-// { dg-do run }
-// { dg-options -std=c++1z }
-// Test C++17 selection statements with initializer, side-effects.
-
-int
-main ()
-{
- int g = 0;
-
- if (g++; g > 1)
- __builtin_abort ();
- if (++g; g > 2)
- __builtin_abort ();
- if (g != 2)
- __builtin_abort ();
-}
}
-void
-f4 (void)
-{
- {
- if (auto i = foo (); i > -1)
- {
- if (i > 5)
- bar (i);
- if (auto j = foo (); true)
- j++;
- j--; // { dg-error "not declared" }
- }
- i = 10; // { dg-error "not declared" }
- }
- i = 10; // { dg-error "not declared" }
-}
-// { dg-options -std=c++1z }
-
-extern int foo (void);
-extern void bar (int), die (void);
-
-void
-f (void)
-{
- if (auto i = foo (); i != -1)
- bar (1);
- else
- die ();
-
- i = 10; // { dg-error "not declared" }
-}
-
-void
-f2 (void)
-{
- switch (auto i = foo (); i)
- {
- case 0:
- bar (i + 1);
- break;
- case 1:
- bar (i + 10);
- break;
- default:
- break;
- }
-
- i = 10; // { dg-error "not declared" }
-}
-
-void
-f3 (void)
-{
- if constexpr (constexpr auto i = sizeof (long); i < 2)
- die ();
- i = 4; // { dg-error "not declared" }
-}
-
-
void
f4 (void)
{
if (status_code c = do_more_stuff (); c != status_code::SUCCESS) { return c; }
return status_code::SUCCESS;
}
-// Testcase from P0305R1
-// { dg-options -std=c++1z }
-
-enum class status_code { SUCCESS };
-extern int get_value ();
-status_code bar (int);
-status_code do_more_stuff (void);
-
-status_code
-foo ()
-{
- int n = get_value ();
- if (status_code c = bar (n); c != status_code::SUCCESS) { return c; }
- if (status_code c = do_more_stuff (); c != status_code::SUCCESS) { return c; }
- return status_code::SUCCESS;
-}
// whatever
}
}
-// Testcase from P0305R1
-// { dg-options -std=c++1z }
-
-#include <string>
-#include <map>
-#include <algorithm>
-
-std::map<int, std::string> m;
-extern int xread (int *);
-extern void publish (int), raise (int);
-
-void
-foo ()
-{
- if (auto it = m.find (10); it != m.end ()) { std::string s = it->second; }
- if (char buf[10]; std::fgets(buf, 10, stdin)) { m[0] += buf; }
- if (int s; int count = xread (&s)) { publish(count); raise(s); }
-
- const char *s;
- if (auto keywords = {"if", "for", "while"};
- std::any_of(keywords.begin(), keywords.end(), [&s](const char* kw) { return s == kw; }))
- {
- // whatever
- }
-}
if (int i = 10, &ir = i; [=]{ return ir; }() != 10)
__builtin_abort ();
}
-// { dg-do run }
-// { dg-options -std=c++1z }
-
-int
-main ()
-{
- if (int i = 10, &ir = i; [=]{ return ir; }() != 10)
- __builtin_abort ();
-}
return 5;
return 0;
}
-// { dg-options -std=c++1z }
-
-int
-f ()
-{
- if (int c = 5;
- int c = 5) // { dg-error "redeclaration" }
- return 5;
- return 0;
-}