[PATCH] PR20716 - Crash when recovering from type in known dependent base (ms-compatibility)

Nikola Smiljanić popizdeh at gmail.com
Wed Aug 20 23:32:13 PDT 2014


We have to extend the check to cover type aliases as well. I've also updated the comment because TypeAliasDecl::Create never calls this constructor overload.

http://reviews.llvm.org/D4992

Files:
  include/clang/AST/DeclTemplate.h
  lib/Sema/SemaDecl.cpp
  test/SemaTemplate/ms-lookup-template-base-classes.cpp

Index: include/clang/AST/DeclTemplate.h
===================================================================
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -236,7 +236,7 @@
       TemplateParams(nullptr) {}
 
   // Construct a template decl with the given name and parameters.
-  // Used when there is not templated element (tt-params, alias?).
+  // Used when there is not templated element (tt-params).
   TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L,
                DeclarationName Name, TemplateParameterList *Params)
     : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr),
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -152,15 +152,17 @@
     auto *TD = TST->getTemplateName().getAsTemplateDecl();
     if (!TD)
       continue;
-    auto *BasePrimaryTemplate = cast<CXXRecordDecl>(TD->getTemplatedDecl());
-    // FIXME: Allow lookup into non-dependent bases of dependent bases, possibly
-    // by calling or integrating with the main LookupQualifiedName mechanism.
-    for (NamedDecl *ND : BasePrimaryTemplate->lookup(&II)) {
-      if (FoundTypeDecl)
-        return ParsedType();
-      FoundTypeDecl = isa<TypeDecl>(ND);
-      if (!FoundTypeDecl)
-        return ParsedType();
+    if (CXXRecordDecl *BasePrimaryTemplate =
+            dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
+      // FIXME: Allow lookup into non-dependent bases of dependent bases, possibly
+      // by calling or integrating with the main LookupQualifiedName mechanism.
+      for (NamedDecl *ND : BasePrimaryTemplate->lookup(&II)) {
+        if (FoundTypeDecl)
+          return ParsedType();
+        FoundTypeDecl = isa<TypeDecl>(ND);
+        if (!FoundTypeDecl)
+          return ParsedType();
+      }
     }
   }
   if (!FoundTypeDecl)
Index: test/SemaTemplate/ms-lookup-template-base-classes.cpp
===================================================================
--- test/SemaTemplate/ms-lookup-template-base-classes.cpp
+++ test/SemaTemplate/ms-lookup-template-base-classes.cpp
@@ -460,3 +460,27 @@
   int x = f<NameFromBase>();
 };
 }
+
+namespace PR20716 {
+template <template <typename T> class A>
+struct B : A<int>
+{
+  void bar() {
+    foo();
+  }
+};
+
+template <typename T>
+struct C {};
+
+template <typename T>
+using D = C<T>;
+
+template <typename T>
+struct E : D<T>
+{
+  void bar() {
+    foo();
+  }
+};
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4992.12739.patch
Type: text/x-patch
Size: 2489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140821/56e0707f/attachment.bin>


More information about the cfe-commits mailing list