Index: clang/lib/Sema/SemaOverload.cpp =================================================================== --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -9779,10 +9779,9 @@ // If other rules cannot determine which is better, CUDA preference is used // to determine which is better. if (S.getLangOpts().CUDA && Cand1.Function && Cand2.Function) { - if (FunctionDecl *Caller = dyn_cast(S.CurContext)) { - return S.IdentifyCUDAPreference(Caller, Cand1.Function) > - S.IdentifyCUDAPreference(Caller, Cand2.Function); - } + FunctionDecl *Caller = dyn_cast(S.CurContext); + return S.IdentifyCUDAPreference(Caller, Cand1.Function) > + S.IdentifyCUDAPreference(Caller, Cand2.Function); } return false; Index: clang/test/SemaCUDA/function-overload.cu =================================================================== --- clang/test/SemaCUDA/function-overload.cu +++ clang/test/SemaCUDA/function-overload.cu @@ -449,3 +449,17 @@ int test_constexpr_overload(C2 &x, C2 &y) { return constexpr_overload(x, y); } + +// Verify no ambiguity for new operator. +void *a = new int; +__device__ void *b = new int; +// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}} + +// Verify no ambiguity for new operator. +template _Tp&& f(); +template()))> +void __test(); + +void foo() { + __test(); +}