[clang] [Clang] Disallow explicit object parameters in more contexts (PR #89078)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 07:26:53 PDT 2024


================
@@ -4845,6 +4845,55 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
       // Check for auto functions and trailing return type and adjust the
       // return type accordingly.
       if (!D.isInvalidType()) {
+        auto isClassType = [&](CXXScopeSpec &SS) {
+          // If there already was an problem with the scope, don’t issue another
+          // error about the explicit object parameter.
+          return SS.isInvalid() ||
+                 isa_and_present<CXXRecordDecl>(S.computeDeclContext(SS));
+        };
+
+        // [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 [class.mem], or
+        // - a lambda-declarator [expr.prim.lambda].
+        DeclaratorContext C = D.getContext();
+        ParmVarDecl *First =
+            FTI.NumParams
+                ? dyn_cast_if_present<ParmVarDecl>(FTI.Params[0].Param)
+                : nullptr;
+
+        auto IsFunctionDecl = D.getInnermostNonParenChunk() == &DeclType;
----------------
AaronBallman wrote:

```suggestion
        bool IsFunctionDecl = D.getInnermostNonParenChunk() == &DeclType;
```


https://github.com/llvm/llvm-project/pull/89078


More information about the cfe-commits mailing list