llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Corentin Jabot (cor3ntin) <details> <summary>Changes</summary> When a specialization was ambiguous, we would mark it as invalid, even if the specialization occured in an immediate context. This would subsequently lead to scenarios where invalid specialization produced no diagnostics, causing crashes during codegen. Fixes #<!-- -->51866 --- Full diff: https://github.com/llvm/llvm-project/pull/147275.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (-1) - (modified) clang/test/SemaTemplate/partial-order.cpp (+26) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9a94c4bcd9980..190eca9a0546e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -901,6 +901,7 @@ Bug Fixes to C++ Support - Fix a bug where private access specifier of overloaded function not respected. (#GH107629) - Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820) - Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254) +- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index a1c7143e3b874..9140f00fcd740 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -4111,7 +4111,6 @@ static ActionResult<CXXRecordDecl *> getPatternForClassTemplateSpecialization( if (Ambiguous) { // Partial ordering did not produce a clear winner. Complain. Inst.Clear(); - ClassTemplateSpec->setInvalidDecl(); S.Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous) << ClassTemplateSpec; diff --git a/clang/test/SemaTemplate/partial-order.cpp b/clang/test/SemaTemplate/partial-order.cpp index db2624d1766bc..2619524b147ae 100644 --- a/clang/test/SemaTemplate/partial-order.cpp +++ b/clang/test/SemaTemplate/partial-order.cpp @@ -47,3 +47,29 @@ namespace GH132562 { // expected-note@-2 {{value of type 'const J' is not implicitly convertible to 'int'}} } // namespace t3 } // namespace GH132562 + +namespace GH51866 { + +template <class> struct Trait; +template <class T> + requires T::one +struct Trait<T> {}; // #gh51866-one +template <class T> + requires T::two +struct Trait<T> {}; // #gh51866-two + +struct Y { + static constexpr bool one = true; + static constexpr bool two = true; +}; + +template <class T> +concept C = sizeof(Trait<T>) != 0; + +static_assert(!C<Y>); + +Trait<Y> t; +// expected-error@-1{{ambiguous partial specializations of 'Trait<GH51866::Y>'}} +// expected-note@#gh51866-one{{partial specialization matches}} +// expected-note@#gh51866-two{{partial specialization matches}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/147275 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits