diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-02-07 10:31:35 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-02-07 10:31:35 +0000 |
| commit | 0e027fb32bab35376fb5370742efabd0ddf5cf23 (patch) | |
| tree | d9d6542ef1b358c017509d040498915875b7d6c9 | |
| parent | b65a913c35de73c154cf7bd935e3df31c480614b (diff) | |
| download | bcm5719-llvm-0e027fb32bab35376fb5370742efabd0ddf5cf23.tar.gz bcm5719-llvm-0e027fb32bab35376fb5370742efabd0ddf5cf23.zip | |
Workaround for friend template instantiation crash in PR5848, from Keir Mierle!
llvm-svn: 95517
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 | ||||
| -rw-r--r-- | clang/test/SemaCXX/templated-friend-decl.cpp | 15 |
2 files changed, 26 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 244b5f511b8..d7820bbc2e6 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -411,9 +411,17 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { Decl *NewND; // Hack to make this work almost well pending a rewrite. - if (ND->getDeclContext()->isRecord()) - NewND = SemaRef.FindInstantiatedDecl(ND, TemplateArgs); - else if (D->wasSpecialization()) { + if (ND->getDeclContext()->isRecord()) { + if (!ND->getDeclContext()->isDependentContext()) { + NewND = SemaRef.FindInstantiatedDecl(ND, TemplateArgs); + } else { + // FIXME: Hack to avoid crashing when incorrectly trying to instantiate + // templated friend declarations. This doesn't produce a correct AST; + // however this is sufficient for some AST analysis. The real solution + // must be put in place during the pending rewrite. See PR5848. + return 0; + } + } else if (D->wasSpecialization()) { // Totally egregious hack to work around PR5866 return 0; } else diff --git a/clang/test/SemaCXX/templated-friend-decl.cpp b/clang/test/SemaCXX/templated-friend-decl.cpp new file mode 100644 index 00000000000..c0034cd72f7 --- /dev/null +++ b/clang/test/SemaCXX/templated-friend-decl.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s + +template <typename T> +struct Foo { + template <typename U> + struct Bar {}; + + // The templated declaration for class Bar should not be instantiated when + // Foo<int> is. This is to protect against PR5848; for now, this "parses" but + // requires a rewrite of the templated friend code to be properly fixed. + template <typename U> + friend struct Bar; +}; + +Foo<int> x; |

