Author: Nathan Ridge Date: 2023-01-30T01:21:09-05:00 New Revision: 68d7f69001c5123d3ec4a93df483a417d981d415
URL: https://github.com/llvm/llvm-project/commit/68d7f69001c5123d3ec4a93df483a417d981d415 DIFF: https://github.com/llvm/llvm-project/commit/68d7f69001c5123d3ec4a93df483a417d981d415.diff LOG: [clangd] Don't show 'auto' type hint when type deduction fails Fixes https://github.com/clangd/clangd/issues/1475 Differential Revision: https://reviews.llvm.org/D142440 Added: Modified: clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/unittests/InlayHintTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index f4e38aeb653ec..a009f84d448ae 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -304,8 +304,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> { return true; } - if (D->getType()->getContainedAutoType()) { - if (!D->getType()->isDependentType()) { + if (auto *AT = D->getType()->getContainedAutoType()) { + if (AT->isDeduced() && !D->getType()->isDependentType()) { // Our current approach is to place the hint on the variable // and accordingly print the full type // (e.g. for `const auto& x = 42`, print `const int&`). diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp index 06f2c055a4d3c..459c51a44d575 100644 --- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1256,6 +1256,13 @@ TEST(TypeHints, StructuredBindings_NoInitializer) { )cpp"); } +TEST(TypeHints, InvalidType) { + assertTypeHints(R"cpp( + auto x = (unknown_type)42; /*error-ok*/ + auto *y = (unknown_ptr)nullptr; + )cpp"); +} + TEST(TypeHints, ReturnTypeDeduction) { assertTypeHints( R"cpp( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits