@@ -586,11 +586,13 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
586
586
if (!Cfg.InlayHints .Parameters )
587
587
return true ;
588
588
589
- // Do not show parameter hints for operator calls written using operator
590
- // syntax or user-defined literals. (Among other reasons, the resulting
589
+ bool IsFunctor = isFunctionObjectCallExpr (E);
590
+ // Do not show parameter hints for user-defined literals or
591
+ // operator calls except for operator(). (Among other reasons, the resulting
591
592
// hints can look awkward, e.g. the expression can itself be a function
592
593
// argument and then we'd get two hints side by side).
593
- if (isa<CXXOperatorCallExpr>(E) || isa<UserDefinedLiteral>(E))
594
+ if ((isa<CXXOperatorCallExpr>(E) && !IsFunctor) ||
595
+ isa<UserDefinedLiteral>(E))
594
596
return true ;
595
597
596
598
auto CalleeDecls = Resolver->resolveCalleeOfCallExpr (E);
@@ -607,7 +609,22 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
607
609
else
608
610
return true ;
609
611
610
- processCall (Callee, {E->getArgs (), E->getNumArgs ()});
612
+ // N4868 [over.call.object]p3 says,
613
+ // The argument list submitted to overload resolution consists of the
614
+ // argument expressions present in the function call syntax preceded by the
615
+ // implied object argument (E).
616
+ //
617
+ // However, we don't have the implied object argument for static
618
+ // operator() per clang::Sema::BuildCallToObjectOfClassType.
619
+ llvm::ArrayRef<const Expr *> Args = {E->getArgs (), E->getNumArgs ()};
620
+ if (IsFunctor)
621
+ // We don't have the implied object argument through
622
+ // a function pointer either.
623
+ if (const CXXMethodDecl *Method =
624
+ dyn_cast_or_null<CXXMethodDecl>(Callee.Decl );
625
+ Method && Method->isInstance ())
626
+ Args = Args.drop_front (1 );
627
+ processCall (Callee, Args);
611
628
return true ;
612
629
}
613
630
@@ -1203,6 +1220,12 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
1203
1220
return Range{HintStart, HintEnd};
1204
1221
}
1205
1222
1223
+ static bool isFunctionObjectCallExpr (CallExpr *E) noexcept {
1224
+ if (auto *CallExpr = dyn_cast<CXXOperatorCallExpr>(E))
1225
+ return CallExpr->getOperator () == OverloadedOperatorKind::OO_Call;
1226
+ return false ;
1227
+ }
1228
+
1206
1229
std::vector<InlayHint> &Results;
1207
1230
ASTContext &AST;
1208
1231
const syntax::TokenBuffer &Tokens;
0 commit comments