[clang-tools-extra] r347119 - [clangd] Fix crash hovering on non-decltype trailing return

Marc-Andre Laperle via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 16 16:41:14 PST 2018


Author: malaperle
Date: Fri Nov 16 16:41:14 2018
New Revision: 347119

URL: http://llvm.org/viewvc/llvm-project?rev=347119&view=rev
Log:
[clangd] Fix crash hovering on non-decltype trailing return

Summary:
More specifically, hovering on "auto" in
auto main() -> int {
    return 0;
}

Signed-off-by: Marc-Andre Laperle <malaperle at gmail.com>

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D54553

Modified:
    clang-tools-extra/trunk/clangd/XRefs.cpp
    clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=347119&r1=347118&r2=347119&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Nov 16 16:41:14 2018
@@ -605,6 +605,7 @@ public:
   // Handle auto return types:
   //- auto foo() {}
   //- auto& foo() {}
+  //- auto foo() -> int {}
   //- auto foo() -> decltype(1+1) {}
   //- operator auto() const { return 10; }
   bool VisitFunctionDecl(FunctionDecl *D) {
@@ -624,12 +625,13 @@ public:
     const AutoType *AT = D->getReturnType()->getContainedAutoType();
     if (AT && !AT->getDeducedType().isNull()) {
       DeducedType = AT->getDeducedType();
-    } else {
+    } else if (auto DT = dyn_cast<DecltypeType>(D->getReturnType())) {
       // auto in a trailing return type just points to a DecltypeType and
       // getContainedAutoType does not unwrap it.
-      const DecltypeType *DT = dyn_cast<DecltypeType>(D->getReturnType());
       if (!DT->getUnderlyingType().isNull())
         DeducedType = DT->getUnderlyingType();
+    } else if (!D->getReturnType().isNull()) {
+      DeducedType = D->getReturnType();
     }
     return true;
   }

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=347119&r1=347118&r2=347119&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Nov 16 16:41:14 2018
@@ -836,6 +836,14 @@ TEST(Hover, All) {
           "",
       },
       {
+          R"cpp(// simple trailing return type
+            ^auto main() -> int {
+              return 0;
+            }
+          )cpp",
+          "int",
+      },
+      {
           R"cpp(// auto function return with trailing type
             struct Bar {};
             ^auto test() -> decltype(Bar()) {




More information about the cfe-commits mailing list