From c785276b926f57d6c606cebc1392facc61d18529 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 11 Jun 2015 23:46:11 +0000 Subject: [PATCH] [modules] Fix crash with multiple levels of default template argument merging. llvm-svn: 239575 --- clang/include/clang/AST/DeclTemplate.h | 2 +- clang/test/Modules/Inputs/submodules-merge-defs/defs.h | 1 + clang/test/Modules/submodules-merge-defs.cpp | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 26d1e99a05b5..0fc9b4947d49 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -265,7 +265,7 @@ public: const DefaultArgStorage *Storage = this; if (auto *Prev = ValueOrInherited.template dyn_cast()) Storage = &Prev->getDefaultArgStorage(); - if (auto *C = ValueOrInherited.template dyn_cast()) + if (auto *C = Storage->ValueOrInherited.template dyn_cast()) return C->Value; return Storage->ValueOrInherited.template get(); } diff --git a/clang/test/Modules/Inputs/submodules-merge-defs/defs.h b/clang/test/Modules/Inputs/submodules-merge-defs/defs.h index 1ab1d1a005be..44259463a102 100644 --- a/clang/test/Modules/Inputs/submodules-merge-defs/defs.h +++ b/clang/test/Modules/Inputs/submodules-merge-defs/defs.h @@ -46,6 +46,7 @@ namespace G { template class K = F> int H(int a = 1); template class K = F> using I = decltype(H()); +template class K = F> struct J {}; namespace NS { struct A {}; diff --git a/clang/test/Modules/submodules-merge-defs.cpp b/clang/test/Modules/submodules-merge-defs.cpp index 6884f56ce7d9..e7c0ad7f0c1c 100644 --- a/clang/test/Modules/submodules-merge-defs.cpp +++ b/clang/test/Modules/submodules-merge-defs.cpp @@ -40,6 +40,9 @@ int pre_ff = F().f(); // expected-error +{{must be imported}} int pre_fg = F().g(); // expected-error +{{must be imported}} // expected-note@defs.h:26 +{{here}} +J<> pre_j; // expected-error {{must be imported}} expected-error {{too few}} +// expected-note@defs.h:49 +{{here}} + // Make definitions from second module visible. #ifdef TEXTUAL #include "import-and-redefine.h" @@ -65,3 +68,6 @@ int post_fg = F().g(); // expected-error@-5 {{no matching member function}} // expected-note@defs.h:34 {{substitution failure}} #endif +J<> post_j; +template class K> struct J; +J<> post_j2;