Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/constexpr-prvalue1.C

raw
1 // PR c++/116416
2 // { dg-do compile { target c++14 } }
3 // { dg-options "-O -fdump-tree-original" }
4
5 struct Str {
6 constexpr Str() {}
7 constexpr Str(const char *instr) {
8 str = instr; length = 0;
9 for (auto index = 0; instr[index]; ++index) {
10 ++length;
11 }
12 }
13 const char *str = nullptr;
14 int length = 0;
15 };
16 extern void callback(Str str);
17 void
18 func1()
19 {
20 callback(Str{"Test1"});
21 }
22 void
23 func2()
24 {
25 Str str{"Test2"};
26 callback(str);
27 }
28
29 // Check that the front end folds both the temporary initializer and
30 // that of 'str'.
31 // { dg-final { scan-tree-dump "{.str=\\(const char \\*\\) \"Test1\", .length=5}" "original" } }
32 // { dg-final { scan-tree-dump "{.str=\\(const char \\*\\) \"Test2\", .length=5}" "original" } }