Skip to content

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

Merged
alsepkow merged 1 commit into
microsoft:mainfrom
ericstone93:user/ruishi/Clang-ambiguous-overloaded-operator-fix
Jun 8, 2026
Merged

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

Conversation

@ericstone93

@ericstone93 ericstone93 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

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

Fixed by casting 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.

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

@alsepkow alsepkow left a comment

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.

LGTM

@inbelic inbelic left a comment

Copy link
Copy Markdown
Collaborator

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
@alsepkow

alsepkow commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@alsepkow alsepkow merged commit d6e0ca4 into microsoft:main Jun 8, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants