Skip to content

Commit e29ac9b

Browse files
authored
[Clang] Do not mark ambiguous specialization invalid. (#147275)
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
1 parent 5adb9a2 commit e29ac9b

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ Bug Fixes to C++ Support
913913
- Fix a bug where private access specifier of overloaded function not respected. (#GH107629)
914914
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
915915
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
916+
- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866)
916917

917918
Bug Fixes to AST Handling
918919
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4111,7 +4111,6 @@ static ActionResult<CXXRecordDecl *> getPatternForClassTemplateSpecialization(
41114111
if (Ambiguous) {
41124112
// Partial ordering did not produce a clear winner. Complain.
41134113
Inst.Clear();
4114-
ClassTemplateSpec->setInvalidDecl();
41154114
S.Diag(PointOfInstantiation,
41164115
diag::err_partial_spec_ordering_ambiguous)
41174116
<< ClassTemplateSpec;

clang/test/SemaTemplate/partial-order.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,29 @@ namespace GH132562 {
4747
// expected-note@-2 {{value of type 'const J' is not implicitly convertible to 'int'}}
4848
} // namespace t3
4949
} // namespace GH132562
50+
51+
namespace GH51866 {
52+
53+
template <class> struct Trait;
54+
template <class T>
55+
requires T::one
56+
struct Trait<T> {}; // #gh51866-one
57+
template <class T>
58+
requires T::two
59+
struct Trait<T> {}; // #gh51866-two
60+
61+
struct Y {
62+
static constexpr bool one = true;
63+
static constexpr bool two = true;
64+
};
65+
66+
template <class T>
67+
concept C = sizeof(Trait<T>) != 0;
68+
69+
static_assert(!C<Y>);
70+
71+
Trait<Y> t;
72+
// expected-error@-1{{ambiguous partial specializations of 'Trait<GH51866::Y>'}}
73+
// expected-note@#gh51866-one{{partial specialization matches}}
74+
// expected-note@#gh51866-two{{partial specialization matches}}
75+
}

0 commit comments

Comments
 (0)