Skip to content

[clang] Fix an out-of-bound crash when checking template partial specializations. #86794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ Bug Fixes to C++ Support
- Fix a crash when instantiating a lambda that captures ``this`` outside of its context. Fixes (#GH85343).
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
following the first `::` were ignored).
- Fix an out-of-bounds crash when checking the validity of template partial specializations. (part of #GH86757).

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,10 +1269,18 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N,
: SourceLocation()));
Atomic.ParameterMapping.emplace(TempArgs, OccurringIndices.count());
}
SourceLocation InstLocBegin =
ArgsAsWritten->arguments().empty()
? ArgsAsWritten->getLAngleLoc()
: ArgsAsWritten->arguments().front().getSourceRange().getBegin();
SourceLocation InstLocEnd =
ArgsAsWritten->arguments().empty()
? ArgsAsWritten->getRAngleLoc()
: ArgsAsWritten->arguments().front().getSourceRange().getEnd();
Sema::InstantiatingTemplate Inst(
S, ArgsAsWritten->arguments().front().getSourceRange().getBegin(),
S, InstLocBegin,
Sema::InstantiatingTemplate::ParameterMappingSubstitution{}, Concept,
ArgsAsWritten->arguments().front().getSourceRange());
{InstLocBegin, InstLocEnd});
if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
return true;

Expand Down
10 changes: 9 additions & 1 deletion clang/test/SemaTemplate/concepts.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -verify %s
// RUN: %clang_cc1 -std=c++20 -ferror-limit 0 -verify %s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ferror-limit 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains many errors, the number of the errors exceeds the default number (19) in clang, which affects the clang behavior (clang will stop parsing when it reaches the error limit).


namespace PR47043 {
template<typename T> concept True = true;
Expand Down Expand Up @@ -1114,3 +1114,11 @@ void foo() {
}

} // namespace GH64808

namespace GH86757_1 {
template <typename...> concept b = false;
template <typename> concept c = b<>;
template <typename d> concept f = c< d >;
template <f> struct e; // expected-note {{}}
template <f d> struct e<d>; // expected-error {{class template partial specialization is not more specialized than the primary template}}
}