Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test18472.d

raw
1 /* REQUIRED_ARGS: -betterC
2 */
3
4 /*******************************************/
5 // https://issues.dlang.org/show_bug.cgi?id=18472
6 // https://github.com/dlang/dmd/pull/14676
7
8 @nogc nothrow pure:
9 immutable(Char)[] format(Char, Args...)(in Char[] fmt, Args args)
10 {
11
12 if (__ctfe)
13 {
14 auto data2 = new char[5];
15 auto data = new Data2;
16 {
17 auto data3 = new Data2;
18 }
19 data2 = cast(char[]) "test2";
20 return data2;
21 }
22 else
23 {
24 return "test";
25 }
26 }
27
28 extern(C) void main()
29 {
30 static assert(getData() == "test");
31 static assert("%s %s".format("test", "test") == "test2", "Not working");
32 assert("%s %s".format("test", "test") == "test", "%s %s".format("test", "test"));
33 assert(getData() == "test2", getData());
34 }
35
36 string getData()
37 {
38 if (__ctfe)
39 {
40 auto data2 = new ubyte[5];
41 auto data = new Data2;
42 return "test";
43 }
44 else
45 {
46 return "test2";
47 }
48 }
49
50 private struct Data2
51 {
52 size_t capacity;
53 }