This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG68d7f69001c5: [clangd] Don't show 'auto' type hint when type deduction fails (authored by nridge).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D142440/new/ https://reviews.llvm.org/D142440 Files: clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/unittests/InlayHintTests.cpp Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1256,6 +1256,13 @@ )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( Index: clang-tools-extra/clangd/InlayHints.cpp =================================================================== --- clang-tools-extra/clangd/InlayHints.cpp +++ clang-tools-extra/clangd/InlayHints.cpp @@ -304,8 +304,8 @@ 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&`).
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1256,6 +1256,13 @@ )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( Index: clang-tools-extra/clangd/InlayHints.cpp =================================================================== --- clang-tools-extra/clangd/InlayHints.cpp +++ clang-tools-extra/clangd/InlayHints.cpp @@ -304,8 +304,8 @@ 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&`).
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits