Skip to content

Commit c09e533

Browse files
ckandelerHighCommander4
authored andcommitted
[clangd] Also mark output arguments of operator call expressions
There's no reason that arguments to e.g. lambda calls should be treated differently than those to "real" functions. Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D128329
1 parent 1b8c735 commit c09e533

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,17 @@ class CollectExtraHighlightings
539539
if (isa<UserDefinedLiteral>(E))
540540
return true;
541541

542-
// FIXME ...here it would make sense though.
543-
if (isa<CXXOperatorCallExpr>(E))
544-
return true;
542+
// FIXME: consider highlighting parameters of some other overloaded
543+
// operators as well
544+
llvm::ArrayRef<const Expr *> Args = {E->getArgs(), E->getNumArgs()};
545+
if (const auto callOp = dyn_cast<CXXOperatorCallExpr>(E)) {
546+
if (callOp->getOperator() != OO_Call)
547+
return true;
548+
Args = Args.drop_front(); // Drop object parameter
549+
}
545550

546551
highlightMutableReferenceArguments(
547-
dyn_cast_or_null<FunctionDecl>(E->getCalleeDecl()),
548-
{E->getArgs(), E->getNumArgs()});
552+
dyn_cast_or_null<FunctionDecl>(E->getCalleeDecl()), Args);
549553

550554
return true;
551555
}

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ sizeof...($TemplateParameter[[Elements]]);
738738
)cpp",
739739
// Modifier for variables passed as non-const references
740740
R"cpp(
741+
struct $Class_decl[[ClassWithOp]] {
742+
void operator()(int);
743+
void operator()(int, int &);
744+
void operator()(int, int, const int &);
745+
};
741746
void $Function_decl[[fun]](int, const int,
742747
int*, const int*,
743748
int&, const int&,
@@ -759,6 +764,13 @@ sizeof...($TemplateParameter[[Elements]]);
759764
$LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]],
760765
$LocalVariable[[array]]
761766
);
767+
[](int){}($LocalVariable[[val]]);
768+
[](int&){}($LocalVariable_usedAsMutableReference[[val]]);
769+
[](const int&){}($LocalVariable[[val]]);
770+
$Class[[ClassWithOp]] $LocalVariable_decl[[c]];
771+
$LocalVariable[[c]]($LocalVariable[[val]]);
772+
$LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
773+
$LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
762774
}
763775
struct $Class_decl[[S]] {
764776
$Class_decl[[S]](int&) {

0 commit comments

Comments
 (0)