[cfe-commits] r82849 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
Douglas Gregor
dgregor at apple.com
Sat Sep 26 00:05:09 PDT 2009
Author: dgregor
Date: Sat Sep 26 02:05:09 2009
New Revision: 82849
URL: http://llvm.org/viewvc/llvm-project?rev=82849&view=rev
Log:
Fix name lookup for friend class templates to consider anything in a
scope *up to and including* the innermost namespace scope, rather than
just searching in the innermost namespace scope.
Added:
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=82849&r1=82848&r2=82849&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sat Sep 26 02:05:09 2009
@@ -579,18 +579,6 @@
Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName,
true);
- } else if (TUK == TUK_Friend) {
- // C++ [namespace.memdef]p3:
- // [...] When looking for a prior declaration of a class or a function
- // declared as a friend, and when the name of the friend class or
- // function is neither a qualified name nor a template-id, scopes outside
- // the innermost enclosing namespace scope are not considered.
- SemanticContext = CurContext;
- while (!SemanticContext->isFileContext())
- SemanticContext = SemanticContext->getLookupParent();
-
- Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName,
- true);
} else {
SemanticContext = CurContext;
Previous = LookupName(S, Name, LookupOrdinaryName, true);
@@ -601,7 +589,27 @@
if (Previous.begin() != Previous.end())
PrevDecl = *Previous.begin();
- if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S))
+ if (PrevDecl && TUK == TUK_Friend) {
+ // C++ [namespace.memdef]p3:
+ // [...] When looking for a prior declaration of a class or a function
+ // declared as a friend, and when the name of the friend class or
+ // function is neither a qualified name nor a template-id, scopes outside
+ // the innermost enclosing namespace scope are not considered.
+ DeclContext *OutermostContext = CurContext;
+ while (!OutermostContext->isFileContext())
+ OutermostContext = OutermostContext->getLookupParent();
+
+ if (OutermostContext->Equals(PrevDecl->getDeclContext()) ||
+ OutermostContext->Encloses(PrevDecl->getDeclContext())) {
+ SemanticContext = PrevDecl->getDeclContext();
+ } else {
+ // Declarations in outer scopes don't matter. However, the outermost
+ // context we computed is the semntic context for our new
+ // declaration.
+ PrevDecl = 0;
+ SemanticContext = OutermostContext;
+ }
+ } else if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S))
PrevDecl = 0;
// If there is a previous declaration with the same name, check
Added: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp?rev=82849&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp Sat Sep 26 02:05:09 2009
@@ -0,0 +1,15 @@
+// RUN: clang-cc -fsyntax-only %s
+
+template<typename T> struct X0 { };
+struct X1 { };
+
+struct Y {
+ template<typename T> union X0;
+ template<typename T> friend union X0;
+
+ union X1;
+ friend union X1;
+};
+
+
+// FIXME: Woefully inadequate for testing
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list