From 410eb27c9c3d9cbc65011559657b93ef94141e0b Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 8 Nov 2025 17:13:21 +0000 Subject: [PATCH 1/3] add check --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaInit.cpp | 2 ++ .../SemaTemplate/temp_arg_nontype_cxx2c.cpp | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6b396e7ba63f3..869223512ab29 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -459,6 +459,8 @@ Bug Fixes in This Version - Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953) - Accept empty enumerations in MSVC-compatible C mode. (#GH114402) - Fixed false-positive shadow diagnostics for lambdas in explicit object member functions. (#GH163731) +- Fixed a incorrect diagnostic for ambiguous function call that use a + designated-initializer as template argument. (#GH166784) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index cc6ddf568d346..58c1c01c9b3ba 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -2937,6 +2937,8 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, } FieldDecl *KnownField = D->getFieldDecl(); + if (KnownField && KnownField->getParent() != RD) + KnownField = nullptr; if (!KnownField) { const IdentifierInfo *FieldName = D->getFieldName(); ValueDecl *VD = SemaRef.tryLookupUnambiguousFieldDecl(RD, FieldName); diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp index c4ac36e263bc8..613956324cb35 100644 --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp @@ -134,3 +134,26 @@ namespace error_on_type_instantiation { template void g(); // expected-note@-1 {{in instantiation of function template specialization}} } + +namespace GH166784 { + +struct A { + int a; +}; +struct B { + int b; +}; +template void f() { + static_assert(a.a == 42); +} +template void f() { + static_assert(b.b == 42); +} + +using T1 = decltype(f<{.a = 42}>()); +using T2 = decltype(f()); + +using T3 = decltype(f<{.b = 42}>()); +using T4 = decltype(f()); + +} // namespace GH166784 From dd70a98b786ef9ce5bba5086edfdd1b7f04179da Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 8 Nov 2025 17:26:08 +0000 Subject: [PATCH 2/3] fix typo --- clang/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 869223512ab29..47ab8497e6f74 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -459,7 +459,7 @@ Bug Fixes in This Version - Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953) - Accept empty enumerations in MSVC-compatible C mode. (#GH114402) - Fixed false-positive shadow diagnostics for lambdas in explicit object member functions. (#GH163731) -- Fixed a incorrect diagnostic for ambiguous function call that use a +- Fixed an incorrect diagnostic for ambiguous function call that use a designated-initializer as template argument. (#GH166784) Bug Fixes to Compiler Builtins From 364de5ae414a3d13b96286cfec9054a6c4f9b35e Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sun, 9 Nov 2025 06:51:09 +0000 Subject: [PATCH 3/3] fix typo --- clang/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 47ab8497e6f74..77902e4e3124d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -459,7 +459,7 @@ Bug Fixes in This Version - Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953) - Accept empty enumerations in MSVC-compatible C mode. (#GH114402) - Fixed false-positive shadow diagnostics for lambdas in explicit object member functions. (#GH163731) -- Fixed an incorrect diagnostic for ambiguous function call that use a +- Fixed an incorrect diagnostic for ambiguous function call that uses a designated-initializer as template argument. (#GH166784) Bug Fixes to Compiler Builtins