[cfe-commits] r95517 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/templated-friend-decl.cpp
Douglas Gregor
dgregor at apple.com
Sun Feb 7 02:31:47 PST 2010
Author: dgregor
Date: Sun Feb 7 04:31:35 2010
New Revision: 95517
URL: http://llvm.org/viewvc/llvm-project?rev=95517&view=rev
Log:
Workaround for friend template instantiation crash in PR5848, from Keir Mierle!
Added:
cfe/trunk/test/SemaCXX/templated-friend-decl.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=95517&r1=95516&r2=95517&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sun Feb 7 04:31:35 2010
@@ -411,9 +411,17 @@
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
Added: cfe/trunk/test/SemaCXX/templated-friend-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/templated-friend-decl.cpp?rev=95517&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/templated-friend-decl.cpp (added)
+++ cfe/trunk/test/SemaCXX/templated-friend-decl.cpp Sun Feb 7 04:31:35 2010
@@ -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;
Propchange: cfe/trunk/test/SemaCXX/templated-friend-decl.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaCXX/templated-friend-decl.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/SemaCXX/templated-friend-decl.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list