Debian Codegraph @

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

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