Skip to content

Clang - Fix use of overloaded operator '+' is ambiguous error#8516

Open
ericstone93 wants to merge 1 commit into
microsoft:mainfrom
ericstone93:user/ruishi/Clang-ambiguous-overloaded-operator-fix
Open

Clang - Fix use of overloaded operator '+' is ambiguous error#8516
ericstone93 wants to merge 1 commit into
microsoft:mainfrom
ericstone93:user/ruishi/Clang-ambiguous-overloaded-operator-fix

Conversation

@ericstone93
Copy link
Copy Markdown

@ericstone93 ericstone93 commented Jun 4, 2026

Why

Resolve the error that shows up when compiled with Clang version 22.1.2 and newer: "use of overloaded operator '+' is ambiguous.".

What

Cast each literal to T (+ T(2.0f), + T(0.0f), + T(4.0f), + T(6.0f)) so the addend has the same type as the operand. This removes the overload ambiguity without changing the values being tested.

Validation

Validated locally in the OS.2020 that all related errors dropped in Clang build.

Wrap the bare integer literals in the DerivativeDdx/DerivativeDdy expected-result expressions in T(...) so the arithmetic resolves cleanly under clang's stricter overload resolution.

Previously: `((A + 2) - (A + 0))` — `A` is of template parameter type `T` (e.g. `HLSLHalf_t`, `HLSLMin16Float_t`). `T + int` has no unambiguous overload for those wrapper types and clang rejects it; MSVC accepted via implicit-conversion ranking.

Now: `((A + T(2.0f)) - (A + T(0.0f)))` — the literal is constructed as `T` first, so `operator+` resolves to the type's own implementation. The value is bit-identical to the previous code path on MSVC.

No behavior change. Affects only the 4 `DEFAULT_OP_1(OpType::DerivativeDd[xy][Fine?], ...)` rows around line 1352.
@ericstone93 ericstone93 marked this pull request as ready for review June 4, 2026 18:55
Copy link
Copy Markdown
Contributor

@alsepkow alsepkow left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@inbelic inbelic left a comment

Choose a reason for hiding this comment

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

LGTUS @Icohedron

@alsepkow alsepkow enabled auto-merge (squash) June 5, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants