diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 829ec2e334a06..79c495d072b2d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -375,6 +375,10 @@ Bug Fixes to C++ Support - Fixed a bug causing destructors of constant-evaluated structured bindings initialized by array elements to be called in the wrong evaluation context. +- Fix crash where ill-formed code was being treated as a deduction guide and + we now produce a diagnostic. Fixes: + (`#65522 `_) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 29362df683653..f12713a9094d8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5414,6 +5414,8 @@ def note_constraint_normalization_here : Note< def note_parameter_mapping_substitution_here : Note< "while substituting into concept arguments here; substitution failures not " "allowed in concept arguments">; +def note_building_deduction_guide_here : Note< + "while building implicit deduction guide first needed here">; def note_lambda_substitution_here : Note< "while substituting into a lambda expression here">; def note_instantiation_contexts_suppressed : Note< diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 00a36696cf904..1ed3df5a011bc 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1075,7 +1075,9 @@ void Sema::PrintInstantiationStack() { << Active->InstantiationRange; break; case CodeSynthesisContext::BuildingDeductionGuides: - llvm_unreachable("unexpected deduction guide in instantiation stack"); + Diags.Report(Active->PointOfInstantiation, + diag::note_building_deduction_guide_here); + break; } } } diff --git a/clang/test/SemaCXX/gh65522.cpp b/clang/test/SemaCXX/gh65522.cpp new file mode 100644 index 0000000000000..2d6331b0372a3 --- /dev/null +++ b/clang/test/SemaCXX/gh65522.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++20 -Wc++17-compat -verify -Wno-unused %s + +class X {}; + +template +class B3 { // expected-note {{candidate template ignored: could not match 'B3' against 'int'}} + template B3(T); // expected-warning 2{{non-type template parameter of type 'X' is incompatible with C++ standards before C++20}} \ + // expected-note {{candidate template ignored: couldn't infer template argument 'x'}} +}; +B3 b3 = 0; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'B3'}} \ + // expected-note {{while building implicit deduction guide first needed here}}