Author: Adam Czachorowski
Date: 2021-10-13T13:15:36+02:00
New Revision: fba563e92b6412f49e7e49299d3d27f04f2e1400

URL: 
https://github.com/llvm/llvm-project/commit/fba563e92b6412f49e7e49299d3d27f04f2e1400
DIFF: 
https://github.com/llvm/llvm-project/commit/fba563e92b6412f49e7e49299d3d27f04f2e1400.diff

LOG: [clangd] TargetFinder: Fix assert-crash on TemplateExpansion args.

Previously we would call getAsTemplate() when kind == TemplateExpansion,
which triggers an assertion. The call is now replaced with
getAsTemplateOrTemplatePattern(), which is exactly the same as
getAsTemplate(), except it allows calls when kind == TemplateExpansion.

No change in behavior for no-assert builds.

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindTarget.cpp
    clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 8419043f4462a..82e4dfeccf43d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -507,7 +507,8 @@ struct TargetFinder {
     // DeclRefExpr).
     if (Arg.getKind() == TemplateArgument::Template ||
         Arg.getKind() == TemplateArgument::TemplateExpansion) {
-      if (TemplateDecl *TD = Arg.getAsTemplate().getAsTemplateDecl()) {
+      if (TemplateDecl *TD =
+              Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()) {
         report(TD, Flags);
       }
     }

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 14cb15a7644b0..9620db9838ae2 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -341,6 +341,15 @@ TEST_F(TargetDeclTest, Types) {
   EXPECT_DECLS("TemplateSpecializationTypeLoc", "template <typename> class T");
   Flags.clear();
 
+  Code = R"cpp(
+  template<template<typename> class ...T>
+  class C {
+    C<[[T...]]> foo;
+    };
+  )cpp";
+  EXPECT_DECLS("TemplateArgumentLoc", {"template <typename> class ...T"});
+  Flags.clear();
+
   Code = R"cpp(
     struct S{};
     S X;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to