yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
1b3887f46
master
1//TEST:SIMPLE(filecheck=CHECK): 2 3// Test to catch compilation time errors with return values in constructors within a NonCopyable struct. 4// A constructor from the callsite's point of view is a function that returns the struct type. 5// A constructor from the inside the body is treated as a function that modifies `this` and not return. 6 7// In the following test-cases where the constructor either returns an expr or no value, 8// within a condition for early exit or not, it automatically gets resolved as 9// return *this; or return; 10 11[__NonCopyableType] struct S 12{ 13 float v; 14} 15 16[__NonCopyableType] struct S1 : S 17{ 18 __init() 19 { 20 this.v = 5; 21 // CHECK-NOT: ([[# @LINE+1]]): error 22 return this; 23 } 24} 25 26[__NonCopyableType] struct S4 : S 27{ 28 __init(float u) 29 { 30 if (u != 0) 31 { 32 this.v = u; 33 // CHECK-NOT: ([[# @LINE+1]]): error 34 return this; 35 } 36 // CHECK-NOT: ([[# @LINE+1]]): error 37 return; 38 } 39} 40 41[__NonCopyableType] struct S2 : S 42{ 43 __init() 44 { 45 S2 t; 46 t.v = 5; 47 // CHECK-NOT: ([[# @LINE+1]]): error 48 return; 49 } 50} 51 52[__NonCopyableType] struct S5 : S 53{ 54 __init(float u) 55 { 56 if (u != 0) 57 { 58 S5 t; 59 t.v = u; 60 // CHECK-NOT: ([[# @LINE+1]]): error 61 return; 62 } 63 // CHECK-NOT: ([[# @LINE+1]]): error 64 return; 65 } 66} 67 68[__NonCopyableType] struct S3 : S 69{ 70 __init() 71 { 72 S3 t; 73 t.v = 5; 74 // CHECK-NOT: ([[# @LINE+1]]): error 75 return t; 76 } 77} 78 79[__NonCopyableType] struct S6 : S 80{ 81 __init(float u) 82 { 83 if (u != 0) 84 { 85 S6 t; 86 t.v = u; 87 // CHECK-NOT: ([[# @LINE+1]]): error 88 return t; 89 } 90 // CHECK-NOT: ([[# @LINE+1]]): error 91 return; 92 } 93} 94 95void main() 96{ 97 S1 s1; 98 S2 s2; 99 S3 s3; 100 S4 s4 = S4(0); 101 S5 s5 = S5(0); 102 S6 s6 = S6(0); 103}