File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -589,6 +589,19 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
589
589
return true ;
590
590
}
591
591
592
+ bool dataTraverseStmtPre (Stmt *S) {
593
+ // Do not show inlay hints for PseudoObjectExprs. They're never
594
+ // genuine user codes in C++.
595
+ //
596
+ // For example, __builtin_dump_struct would expand to a PseudoObjectExpr
597
+ // that includes a couple of calls to a printf function. Printing parameter
598
+ // names for that anyway would end up with duplicate parameter names (which,
599
+ // however, got de-duplicated after visiting) for the printf function.
600
+ if (AST.getLangOpts ().CPlusPlus && isa<PseudoObjectExpr>(S))
601
+ return false ;
602
+ return true ;
603
+ }
604
+
592
605
bool VisitCallExpr (CallExpr *E) {
593
606
if (!Cfg.InlayHints .Parameters )
594
607
return true ;
Original file line number Diff line number Diff line change @@ -1724,6 +1724,30 @@ TEST(InlayHints, RestrictRange) {
1724
1724
ElementsAre (labelIs (" : int" ), labelIs (" : char" )));
1725
1725
}
1726
1726
1727
+ TEST (ParameterHints, PseudoObjectExpr) {
1728
+ Annotations Code (R"cpp(
1729
+ struct S {
1730
+ __declspec(property(get=GetX, put=PutX)) int x[];
1731
+ int GetX(int y, int z) { return 42 + y; }
1732
+ void PutX(int y) { x = y; } // Not `x = y: y`
1733
+ };
1734
+
1735
+ int printf(const char *Format, ...);
1736
+
1737
+ int main() {
1738
+ S s;
1739
+ __builtin_dump_struct(&s, printf); // Not `Format: __builtin_dump_struct()`
1740
+ printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
1741
+ return s.x[1][2]; // Not `x[y: 1][z: 2]`
1742
+ }
1743
+ )cpp" );
1744
+ auto TU = TestTU::withCode (Code.code ());
1745
+ TU.ExtraArgs .push_back (" -fms-extensions" );
1746
+ auto AST = TU.build ();
1747
+ EXPECT_THAT (inlayHints (AST, std::nullopt),
1748
+ ElementsAre (HintMatcher (ExpectedHint{" Format: " , " Param" }, Code)));
1749
+ }
1750
+
1727
1751
TEST (ParameterHints, ArgPacksAndConstructors) {
1728
1752
assertParameterHints (
1729
1753
R"cpp(
You can’t perform that action at this time.
0 commit comments