diff --git a/tools/clang/test/HLSLFileCheck/hlsl/operator_overloading/subscript-operator.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/operator_overloading/subscript-operator.hlsl new file mode 100644 index 0000000000..063952f126 --- /dev/null +++ b/tools/clang/test/HLSLFileCheck/hlsl/operator_overloading/subscript-operator.hlsl @@ -0,0 +1,26 @@ +// RUN: %dxc -T lib_6_4 -HV 2021 -ast-dump %s | FileCheck %s + +struct MyVector3 { + float3 V; + + float operator[](int x) { + return V[x]; + } +}; + +float SomeFun(const MyVector3 V, int Idx) { + return V[Idx]; +} + +// This test verifies that under HLSL 2021, overload resolution for user-defined +// subscript operators follows HLSL overload resolution rules and ignores the +// const-ness of the implicit object parameter. + +// CHECK: CXXRecordDecl {{0x[0-9a-fA-F]+}} {{.*}} referenced struct MyVector3 definition +// CHECK: FieldDecl {{0x[0-9a-fA-F]+}} col:12 referenced V 'float3':'vector' +// CHECK-NEXT: CXXMethodDecl [[Operator:0x[0-9a-fA-F]+]] line:6:11 used operator[] 'float (int)' + +// CHECK: FunctionDecl {{0x[0-9a-fA-F]+}} line:11:7 SomeFun 'float (const MyVector3, int)' +// CHECK: CXXOperatorCallExpr {{0x[0-9a-fA-F]+}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{0x[0-9a-fA-F]+}} 'float (*)(int)' +// CHECK-NEXT: DeclRefExpr {{0x[0-9a-fA-F]+}} 'float (int)' lvalue CXXMethod [[Operator]] 'operator[]' 'float (int)'