[cfe-commits] r143614 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplate.cpp test/SemaCXX/friend-out-of-line.cpp
Douglas Gregor
dgregor at apple.com
Thu Nov 3 09:37:14 PDT 2011
Author: dgregor
Date: Thu Nov 3 11:37:14 2011
New Revision: 143614
URL: http://llvm.org/viewvc/llvm-project?rev=143614&view=rev
Log:
When we're checking a friend function template in an out-of-line class
definition, we may not have a scope corresponding to the namespace
where that friend function template actually lives. Work around this
issue by faking up a scope with the appropriate DeclContext.
This is a bit of a hack, but it fixes <rdar://problem/10204947>.
Added:
cfe/trunk/test/SemaCXX/friend-out-of-line.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=143614&r1=143613&r2=143614&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Nov 3 11:37:14 2011
@@ -10050,7 +10050,7 @@
diag::err_friend_is_member);
DCScope = getScopeForDeclContext(S, DC);
-
+
// C++ [class.friend]p6:
// A function can be defined in a friend declaration of a class if and
// only if the class is a non-local class (9.8), the function name is
@@ -10142,6 +10142,15 @@
}
}
+ // FIXME: This is an egregious hack to cope with cases where the scope stack
+ // does not contain the declaration context, i.e., in an out-of-line
+ // definition of a class.
+ Scope FakeDCScope(S, Scope::DeclScope, Diags);
+ if (!DCScope) {
+ FakeDCScope.setEntity(DC);
+ DCScope = &FakeDCScope;
+ }
+
bool AddToScope = true;
NamedDecl *ND = ActOnFunctionDeclarator(DCScope, D, DC, TInfo, Previous,
move(TemplateParams), AddToScope);
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=143614&r1=143613&r2=143614&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Nov 3 11:37:14 2011
@@ -4455,6 +4455,9 @@
/// false. Otherwise, issues a diagnostic and returns true.
bool
Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) {
+ if (!S)
+ return false;
+
// Find the nearest enclosing declaration scope.
while ((S->getFlags() & Scope::DeclScope) == 0 ||
(S->getFlags() & Scope::TemplateParamScope) != 0)
Added: cfe/trunk/test/SemaCXX/friend-out-of-line.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/friend-out-of-line.cpp?rev=143614&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/friend-out-of-line.cpp (added)
+++ cfe/trunk/test/SemaCXX/friend-out-of-line.cpp Thu Nov 3 11:37:14 2011
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/10204947>
+namespace N {
+ class X;
+};
+
+class N::X {
+ template<typename T> friend const T& f(const X&);
+ friend const int& g(const X&);
+ friend class Y;
+};
Propchange: cfe/trunk/test/SemaCXX/friend-out-of-line.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaCXX/friend-out-of-line.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/SemaCXX/friend-out-of-line.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list