summaryrefslogtreecommitdiff
path: root/test/SemaTemplate
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2013-03-14 05:13:41 +0000
committerJohn McCall <rjmccall@apple.com>2013-03-14 05:13:41 +0000
commite34db6b3e772e9832e1f6de1f23457076ffbec88 (patch)
tree21d1b9aafdebff78f0f1f90197cd962133d83b2f /test/SemaTemplate
parentfaf01f02f6f3844cec6c2ddca297b4f33b361960 (diff)
downloadclang-e34db6b3e772e9832e1f6de1f23457076ffbec88.tar.gz
Flag that friend function definitions are "late parsed" so that
template instantiation will still consider them to be definitions if we instantiate the containing class before we get around to parsing the friend. This seems like a legitimate use of "late template parsed" to me, but I'd appreciate it if someone responsible for the MS feature would look over this. This file already appears to access AST nodes directly, which is arguably not kosher in the parser, but the performance of this path matters enough that perpetuating the sin is justifiable. Probably we ought to reconsider this policy for very simple manipulations like this. The reason this entire thing is necessary is that function template instantiation plays some very gross games in order to not associate an instantiated function template with the class it came from unless it's a definition, and the reason *that's* necessary is that the AST currently cannot represent the instantiation history of individual function template declarations, but instead tracks it in common for the entire function template. That probably prevents us from correctly reporting ill-formed calls to ambiguously instantiated friend function templates. rdar://12350696 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177003 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r--test/SemaTemplate/friend-template.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp
index 9acbfdcea2..8a478777eb 100644
--- a/test/SemaTemplate/friend-template.cpp
+++ b/test/SemaTemplate/friend-template.cpp
@@ -302,3 +302,23 @@ namespace PR12585 {
H<int> h1; // ok
H<char> h2; // expected-note {{instantiation}}
}
+
+// Ensure that we can still instantiate a friend function template
+// after the friend declaration is instantiated during the delayed
+// parsing of a member function, but before the friend function has
+// been parsed.
+namespace rdar12350696 {
+ template <class T> struct A {
+ void foo() {
+ A<int> a;
+ }
+ template <class U> friend void foo(const A<U> & a) {
+ int array[sizeof(T) == sizeof(U) ? -1 : 1]; // expected-error {{negative size}}
+ }
+ };
+
+ void test() {
+ A<int> b;
+ foo(b); // expected-note {{in instantiation}}
+ }
+}