Skip to content

[C++20] Fix crash with invalid concept requirement #138877

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
May 7, 2025
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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ Bug Fixes to C++ Support
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
- No longer crashes when instantiating invalid variable template specialization
whose type depends on itself. (#GH51347), (#GH55872)
- Improved parser recovery of invalid requirement expressions. In turn, this
fixes crashes from follow-on processing of the invalid requirement. (#GH138820)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3706,8 +3706,10 @@ ExprResult Parser::ParseRequiresExpression() {
SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
break;
}
// If there's an error consuming the closing bracket, consumeClose()
// will handle skipping to the nearest recovery point for us.
if (ExprBraces.consumeClose())
ExprBraces.skipToEnd();
break;

concepts::Requirement *Req = nullptr;
SourceLocation NoexceptLoc;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaCXX/concept-crash-on-diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ concept is_foo_concept = __is_same(foo::bar, T);
// expected-error@-1 {{'bar' is a private member of 'GH131530::foo'}}

}

namespace GH138820 {
int a;
template<typename T>
concept atomicish = requires() {
{ // expected-note {{to match this '{'}}
a
... // expected-error {{expected '}'}}
};
};
atomicish<int> f(); // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
} // namespace GH138820
Loading