Skip to content

[Clang][Lex] Fix parsing of nested requirement to prevent flowing off the end of token stream #73691

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
Nov 30, 2023
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
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ Bug Fixes to C++ Support
completes (except deduction guides). Fixes:
(`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_)

- Fix crash when parsing nested requirement. Fixes:
(`#73112 <https://github.com/llvm/llvm-project/issues/73112>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3635,10 +3635,12 @@ ExprResult Parser::ParseRequiresExpression() {
auto Res = TryParseParameterDeclarationClause();
if (Res != TPResult::False) {
// Skip to the closing parenthesis
// FIXME: Don't traverse these tokens twice (here and in
// TryParseParameterDeclarationClause).
unsigned Depth = 1;
while (Depth != 0) {
bool FoundParen = SkipUntil(tok::l_paren, tok::r_paren,
SkipUntilFlags::StopBeforeMatch);
if (!FoundParen)
break;
if (Tok.is(tok::l_paren))
Depth++;
else if (Tok.is(tok::r_paren))
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Parser/cxx2a-concepts-requires-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ template <int N>
requires requires {
typename BitInt<N>; // ok
} using r44 = void;

namespace GH73112 {
void f() {
requires { requires(int; } // expected-error {{expected ')'}} \
// expected-error {{expected expression}} \
// expected-note {{to match this '('}}
}
}