aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorKrystian Stasiowski <sdkrystian@gmail.com>2024-04-17 11:41:03 -0400
committerGitHub <noreply@github.com>2024-04-17 11:41:03 -0400
commit8656d4c6a7a742c6fa6ee02c2ace7415163e65e4 (patch)
tree2701e4d0a70ba5960fe09d322053e1f8f6e8fde5 /clang/lib/Parse/ParseDecl.cpp
parentb854a2323337be2633b1135f590678a17e9d1ade (diff)
downloadllvm-8656d4c6a7a742c6fa6ee02c2ace7415163e65e4.zip
llvm-8656d4c6a7a742c6fa6ee02c2ace7415163e65e4.tar.gz
llvm-8656d4c6a7a742c6fa6ee02c2ace7415163e65e4.tar.bz2
[Clang][Parse] Diagnose requires expressions with explicit object parameters (#88974)
Clang currently allows the following: ``` auto x = requires (this int) { true; }; ``` This patch addresses that.
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 274ee7b..5f26b5a 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7660,8 +7660,21 @@ void Parser::ParseParameterDeclarationClause(
// Parse a C++23 Explicit Object Parameter
// We do that in all language modes to produce a better diagnostic.
SourceLocation ThisLoc;
- if (getLangOpts().CPlusPlus && Tok.is(tok::kw_this))
+ if (getLangOpts().CPlusPlus && Tok.is(tok::kw_this)) {
ThisLoc = ConsumeToken();
+ // C++23 [dcl.fct]p6:
+ // An explicit-object-parameter-declaration is a parameter-declaration
+ // with a this specifier. An explicit-object-parameter-declaration
+ // shall appear only as the first parameter-declaration of a
+ // parameter-declaration-list of either:
+ // - a member-declarator that declares a member function, or
+ // - a lambda-declarator.
+ //
+ // The parameter-declaration-list of a requires-expression is not such
+ // a context.
+ if (DeclaratorCtx == DeclaratorContext::RequiresExpr)
+ Diag(ThisLoc, diag::err_requires_expr_explicit_object_parameter);
+ }
ParseDeclarationSpecifiers(DS, /*TemplateInfo=*/ParsedTemplateInfo(),
AS_none, DeclSpecContext::DSC_normal,