Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ line upon naming the release. Refer to previous for appropriate section names.

#### Other Changes
- 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.

### Version 1.9.2602

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
27 changes: 27 additions & 0 deletions tools/clang/test/SemaHLSL/conversion-operator-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 {
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;
}
};