Skip to content
10 changes: 8 additions & 2 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ line upon naming the release. Refer to previous for appropriate section names.

#### Bug Fixes

- Fixed non-deterministic DXIL/PDB output when compiling shaders with resource arrays, debug info, and SM 6.6+. [#8171](https://github.com/microsoft/DirectXShaderCompiler/issues/8171)
- Fixed non-deterministic DXIL/PDB output when compiling shaders with resource
arrays, debug info, and SM 6.6+.
[#8171](https://github.com/microsoft/DirectXShaderCompiler/issues/8171)
- Fixed mesh shader semantics that were incorrectly case sensitive.
- User-defined conversion operators (e.g., `operator float4()`) now produce an
error instead of being silently ignored.
[#5103](https://github.com/microsoft/DirectXShaderCompiler/pull/8206)
- DXIL validation: added validation for `CreateHandleFromBinding`.
- DXIL validation now rejects non-standard integer bit widths (e.g. `i25`) in instructions.
- DXIL validation now rejects non-standard integer bit widths (e.g. `i25`) in
instructions.

#### Other Changes

Expand Down
2 changes: 2 additions & 0 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7550,6 +7550,8 @@ def err_hlsl_matrix_member_zero_in_one_based: Error<
"the digit '0' is used in '%0', but the syntax is for one-based rows and columns">;
def err_hlsl_overloading_operator_disallowed: Error<
"overloading %select{|non-member }1%0 is not allowed">;
def err_hlsl_unsupported_conversion_operator: Error<
"conversion operator overloading is not allowed">;
def err_hlsl_vector_member_bad_format: Error<
"invalid format for vector swizzle '%0'">;
def err_hlsl_vector_member_empty: Error<
Expand Down
8 changes: 8 additions & 0 deletions tools/clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6956,6 +6956,14 @@ static void extendRight(SourceRange &R, const SourceRange &After) {
/// well-formed type for the conversion operator.
void Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
StorageClass& SC) {
// HLSL Change Starts
if (getLangOpts().HLSL) {
Diag(D.getIdentifierLoc(), diag::err_hlsl_unsupported_conversion_operator);
D.setInvalidType();
return;
}
// HLSL Change Ends

// C++ [class.conv.fct]p1:
// Neither parameter types nor return type can be specified. The
// type of a conversion function (8.3.5) is "function taking no
Expand Down
37 changes: 37 additions & 0 deletions tools/clang/test/SemaHLSL/conversion-operator-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %dxc -Tlib_6_3 -verify -HV 2021 %s

// This test verifies that dxcompiler generates an error when defining
// a conversion operator (cast operator), which is not supported in HLSL.

struct MyStruct {
float4 f;

// expected-error@+1 {{conversion operator overloading is not allowed}}
operator float4() {
return 42;
}
};

struct AnotherStruct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a test for the template-dependent case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one

int x;

// expected-error@+1 {{conversion operator overloading is not allowed}}
operator int() {
return x;
}

// expected-error@+1 {{conversion operator overloading is not allowed}}
operator bool() {
return x != 0;
}
};

template<typename T>
struct TemplateStruct {
T value;

// expected-error@+1 {{conversion operator overloading is not allowed}}
operator T() {
return value;
}
};
Loading