Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/cpp0x/temp-extend2.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // PR c++/92831 | |
2 // { dg-do run { target c++11 } } | |
3 | |
4 template<typename T> using id = T; | |
5 struct S { S () { s++; } ~S () { s--; } S (int) { s++; } static int s; }; | |
6 int S::s = 0; | |
7 | |
8 void | |
9 bar (bool cond, bool cond2) | |
10 { | |
11 if (S::s != (cond ? cond2 ? 7 : 5 : cond2 ? 8 : 9)) | |
12 __builtin_abort (); | |
13 } | |
14 | |
15 void | |
16 foo (bool cond, bool cond2) | |
17 { | |
18 int i = 1; | |
19 // temporary array has same lifetime as a | |
20 S&& a = id<S[3]>{1, 2, 3}[i]; | |
21 // temporary S has same lifetime as b | |
22 const S& b = static_cast<const S&>(0); | |
23 // exactly one of the four temporaries is lifetime-extended | |
24 S&& c = cond ? cond2 ? id<S[3]>{1, 2, 3}[i] : static_cast<S&&>(0) | |
25 : cond2 ? id<S[4]>{1, 2, 3, 4}[i] : id<S[5]>{1, 2, 3, 4, 5}[i]; | |
26 bar (cond, cond2); | |
27 } | |
28 | |
29 int | |
30 main () | |
31 { | |
32 foo (true, true); | |
33 foo (true, false); | |
34 foo (false, true); | |
35 foo (false, false); | |
36 } |