[cfe-commits] r80044 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/AST/ASTContext.cpp lib/Parse/MinimalAction.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTentative.cpp lib/Parse/Parser.cpp lib/Sema/Sema.h lib/Sema/SemaCXXScopeSpec.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp lib/Sema/SemaTemplate.cpp lib/Sema/TreeTransform.h test/SemaTemplate/dependent-type-identity.cpp test/SemaTemplate/nested-template.cpp
Douglas Gregor
dgregor at apple.com
Tue Aug 25 15:51:20 PDT 2009
Author: dgregor
Date: Tue Aug 25 17:51:20 2009
New Revision: 80044
URL: http://llvm.org/viewvc/llvm-project?rev=80044&view=rev
Log:
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Parse/MinimalAction.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaTemplate/dependent-type-identity.cpp
cfe/trunk/test/SemaTemplate/nested-template.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Aug 25 17:51:20 2009
@@ -190,14 +190,28 @@
virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
const CXXScopeSpec *SS = 0) = 0;
- /// \brief Determines whether the identifier II is a template name
- /// in the current scope. If so, the kind of template name is
- /// returned, and \p TemplateDecl receives the declaration. An
- /// optional CXXScope can be passed to indicate the C++ scope in
- /// which the identifier will be found.
+ /// \brief Determine whether the given identifier refers to the name of a
+ /// template.
+ ///
+ /// \param II the identifier that we are querying to determine whether it
+ /// is a template.
+ ///
+ /// \param S the scope in which name lookup occurs
+ ///
+ /// \param SS the C++ scope specifier that precedes the template name, if
+ /// any.
+ ///
+ /// \param EnteringContext whether we are potentially entering the context
+ /// referred to by the scope specifier \p SS
+ ///
+ /// \param Template if the name does refer to a template, the declaration
+ /// of the template that the name refers to.
+ ///
+ /// \returns the kind of template that this name refers to.
virtual TemplateNameKind isTemplateName(const IdentifierInfo &II, Scope *S,
- TemplateTy &Template,
- const CXXScopeSpec *SS = 0) = 0;
+ const CXXScopeSpec *SS,
+ bool EnteringContext,
+ TemplateTy &Template) = 0;
/// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
/// global scope ('::').
@@ -216,7 +230,8 @@
const CXXScopeSpec &SS,
SourceLocation IdLoc,
SourceLocation CCLoc,
- IdentifierInfo &II) {
+ IdentifierInfo &II,
+ bool EnteringContext) {
return 0;
}
@@ -1990,9 +2005,28 @@
virtual bool isCurrentClassName(const IdentifierInfo& II, Scope *S,
const CXXScopeSpec *SS);
+ /// \brief Determine whether the given identifier refers to the name of a
+ /// template.
+ ///
+ /// \param II the identifier that we are querying to determine whether it
+ /// is a template.
+ ///
+ /// \param S the scope in which name lookup occurs
+ ///
+ /// \param SS the C++ scope specifier that precedes the template name, if
+ /// any.
+ ///
+ /// \param EnteringContext whether we are potentially entering the context
+ /// referred to by the scope specifier \p SS
+ ///
+ /// \param Template if the name does refer to a template, the declaration
+ /// of the template that the name refers to.
+ ///
+ /// \returns the kind of template that this name refers to.
virtual TemplateNameKind isTemplateName(const IdentifierInfo &II, Scope *S,
- TemplateTy &Template,
- const CXXScopeSpec *SS = 0);
+ const CXXScopeSpec *SS,
+ bool EnteringContext,
+ TemplateTy &Template);
/// ActOnDeclarator - If this is a typedef declarator, we modify the
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Aug 25 17:51:20 2009
@@ -318,12 +318,12 @@
/// for expressions in C.
///
/// This returns true if the token was annotated.
- bool TryAnnotateTypeOrScopeToken();
+ bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false);
/// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
/// annotates C++ scope specifiers. This returns true if the token was
/// annotated.
- bool TryAnnotateCXXScopeToken();
+ bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
/// TentativeParsingAction - An object that is used as a kind of "tentative
/// parsing transaction". It gets instantiated to mark the token position and
@@ -775,7 +775,8 @@
/// was parsed from the token stream. Note that this routine will not parse
/// ::new or ::delete, it will just leave them in the token stream.
///
- bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS);
+ bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
+ bool EnteringContext = false);
//===--------------------------------------------------------------------===//
// C++ 5.2p1: C++ Casts
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Aug 25 17:51:20 2009
@@ -2235,13 +2235,7 @@
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate: {
QualType T = getCanonicalType(QualType(NNS->getAsType(), 0));
- NestedNameSpecifier *Prefix = 0;
-
- // FIXME: This isn't the right check!
- if (T->isDependentType())
- Prefix = getCanonicalNestedNameSpecifier(NNS->getPrefix());
-
- return NestedNameSpecifier::Create(*this, Prefix,
+ return NestedNameSpecifier::Create(*this, 0,
NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
T.getTypePtr());
}
Modified: cfe/trunk/lib/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/MinimalAction.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/lib/Parse/MinimalAction.cpp Tue Aug 25 17:51:20 2009
@@ -159,8 +159,9 @@
TemplateNameKind
MinimalAction::isTemplateName(const IdentifierInfo &II, Scope *S,
- TemplateTy &TemplateDecl,
- const CXXScopeSpec *SS) {
+ const CXXScopeSpec *SS,
+ bool EnteringScope,
+ TemplateTy &TemplateDecl) {
return TNK_Non_template;
}
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Aug 25 17:51:20 2009
@@ -728,7 +728,7 @@
case tok::coloncolon: // ::foo::bar
// Annotate C++ scope specifiers. If we get one, loop.
- if (TryAnnotateCXXScopeToken())
+ if (TryAnnotateCXXScopeToken(true))
continue;
goto DoneWithDeclSpec;
@@ -743,7 +743,7 @@
->Kind == TNK_Type_template) {
// We have a qualified template-id, e.g., N::A<int>
CXXScopeSpec SS;
- ParseOptionalCXXScopeSpecifier(SS);
+ ParseOptionalCXXScopeSpecifier(SS, true);
assert(Tok.is(tok::annot_template_id) &&
"ParseOptionalCXXScopeSpecifier not working");
AnnotateTemplateIdTokenAsType(&SS);
@@ -820,7 +820,7 @@
case tok::identifier: {
// In C++, check to see if this is a scope specifier like foo::bar::, if
// so handle it as such. This is important for ctor parsing.
- if (getLang().CPlusPlus && TryAnnotateCXXScopeToken())
+ if (getLang().CPlusPlus && TryAnnotateCXXScopeToken(true))
continue;
// This identifier can only be a typedef name if we haven't already seen
@@ -2023,7 +2023,7 @@
(Tok.is(tok::coloncolon) || Tok.is(tok::identifier) ||
Tok.is(tok::annot_cxxscope))) {
CXXScopeSpec SS;
- if (ParseOptionalCXXScopeSpecifier(SS)) {
+ if (ParseOptionalCXXScopeSpecifier(SS, true)) {
if(Tok.isNot(tok::star)) {
// The scope spec really belongs to the direct-declarator.
D.getCXXScopeSpec() = SS;
@@ -2180,7 +2180,7 @@
if (D.mayHaveIdentifier()) {
// ParseDeclaratorInternal might already have parsed the scope.
bool afterCXXScope = D.getCXXScopeSpec().isSet() ||
- ParseOptionalCXXScopeSpecifier(D.getCXXScopeSpec());
+ ParseOptionalCXXScopeSpecifier(D.getCXXScopeSpec(), true);
if (afterCXXScope) {
// Change the declaration context for name lookup, until this function
// is exited (and the declarator has been parsed).
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Aug 25 17:51:20 2009
@@ -534,7 +534,7 @@
// Parse the (optional) nested-name-specifier.
CXXScopeSpec SS;
- if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS))
+ if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS, true))
if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id))
Diag(Tok, diag::err_expected_ident);
@@ -809,7 +809,7 @@
// Parse optional '::' and optional nested-name-specifier.
CXXScopeSpec SS;
- ParseOptionalCXXScopeSpecifier(SS);
+ ParseOptionalCXXScopeSpecifier(SS, true);
// The location of the base class itself.
SourceLocation BaseLoc = Tok.getLocation();
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Aug 25 17:51:20 2009
@@ -30,10 +30,11 @@
/// nested-name-specifier identifier '::'
/// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
///
-bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) {
+bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
+ bool EnteringContext) {
assert(getLang().CPlusPlus &&
"Call sites of this function should be guarded by checking for C++");
-
+
if (Tok.is(tok::annot_cxxscope)) {
SS.setScopeRep(Tok.getAnnotationValue());
SS.setRange(Tok.getAnnotationRange());
@@ -106,7 +107,6 @@
if (TemplateId->Kind == TNK_Type_template ||
TemplateId->Kind == TNK_Dependent_template_name) {
AnnotateTemplateIdTokenAsType(&SS);
- SS.setScopeRep(0);
assert(Tok.is(tok::annot_typename) &&
"AnnotateTemplateIdTokenAsType isn't working");
@@ -164,7 +164,8 @@
continue;
SS.setScopeRep(
- Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, II));
+ Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, II,
+ EnteringContext));
SS.setEndLoc(CCLoc);
continue;
}
@@ -173,8 +174,9 @@
// type-name '<'
if (Next.is(tok::less)) {
TemplateTy Template;
- if (TemplateNameKind TNK = Actions.isTemplateName(II, CurScope,
- Template, &SS)) {
+ if (TemplateNameKind TNK = Actions.isTemplateName(II, CurScope, &SS,
+ EnteringContext,
+ Template)) {
// We have found a template name, so annotate this this token
// with a template-id annotation. We do not permit the
// template-id to be translated into a type annotation,
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Tue Aug 25 17:51:20 2009
@@ -409,7 +409,7 @@
while (1) {
if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier))
- TryAnnotateCXXScopeToken();
+ TryAnnotateCXXScopeToken(true);
if (Tok.is(tok::star) || Tok.is(tok::amp) || Tok.is(tok::caret) ||
(Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Aug 25 17:51:20 2009
@@ -870,7 +870,7 @@
///
/// Note that this routine emits an error if you call it with ::new or ::delete
/// as the current tokens, so only call it in contexts where these are invalid.
-bool Parser::TryAnnotateTypeOrScopeToken() {
+bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) {
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)
|| Tok.is(tok::kw_typename)) &&
"Cannot be a type or scope token!");
@@ -884,7 +884,7 @@
// simple-template-id
SourceLocation TypenameLoc = ConsumeToken();
CXXScopeSpec SS;
- bool HadNestedNameSpecifier = ParseOptionalCXXScopeSpecifier(SS);
+ bool HadNestedNameSpecifier = ParseOptionalCXXScopeSpecifier(SS, false);
if (!HadNestedNameSpecifier) {
Diag(Tok.getLocation(), diag::err_expected_qualified_after_typename);
return false;
@@ -928,7 +928,7 @@
CXXScopeSpec SS;
if (getLang().CPlusPlus)
- ParseOptionalCXXScopeSpecifier(SS);
+ ParseOptionalCXXScopeSpecifier(SS, EnteringContext);
if (Tok.is(tok::identifier)) {
// Determine whether the identifier is a type name.
@@ -960,7 +960,7 @@
TemplateTy Template;
if (TemplateNameKind TNK
= Actions.isTemplateName(*Tok.getIdentifierInfo(),
- CurScope, Template, &SS))
+ CurScope, &SS, EnteringContext, Template))
if (AnnotateTemplateIdToken(Template, TNK, &SS)) {
// If an unrecoverable error occurred, we need to return true here,
// because the token stream is in a damaged state. We may not return
@@ -1015,14 +1015,14 @@
///
/// Note that this routine emits an error if you call it with ::new or ::delete
/// as the current tokens, so only call it in contexts where these are invalid.
-bool Parser::TryAnnotateCXXScopeToken() {
+bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) {
assert(getLang().CPlusPlus &&
"Call sites of this function should be guarded by checking for C++");
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
"Cannot be a type or scope token!");
CXXScopeSpec SS;
- if (!ParseOptionalCXXScopeSpecifier(SS))
+ if (!ParseOptionalCXXScopeSpecifier(SS, EnteringContext))
return Tok.is(tok::annot_template_id);
// Push the current token back into the token stream (or revert it if it is
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Aug 25 17:51:20 2009
@@ -1265,7 +1265,8 @@
LookupNameKind NameKind,
bool RedeclarationOnly = false,
bool AllowBuiltinCreation = false,
- SourceLocation Loc = SourceLocation());
+ SourceLocation Loc = SourceLocation(),
+ bool EnteringContext = false);
ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II);
ObjCCategoryImplDecl *LookupObjCCategoryImpl(IdentifierInfo *II);
@@ -1951,7 +1952,8 @@
const CXXScopeSpec &SS,
SourceLocation IdLoc,
SourceLocation CCLoc,
- IdentifierInfo &II);
+ IdentifierInfo &II,
+ bool EnteringContext);
/// ActOnCXXNestedNameSpecifier - Called during parsing of a
/// nested-name-specifier that involves a template-id, e.g.,
@@ -2205,8 +2207,9 @@
// C++ Templates [C++ 14]
//
virtual TemplateNameKind isTemplateName(const IdentifierInfo &II, Scope *S,
- TemplateTy &Template,
- const CXXScopeSpec *SS = 0);
+ const CXXScopeSpec *SS,
+ bool EnteringContext,
+ TemplateTy &Template);
bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl);
Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Aug 25 17:51:20 2009
@@ -48,11 +48,11 @@
return Record;
if (EnteringContext) {
- // We are entering the context of the nested name specifier, so try to
- // match the nested name specifier to either a primary class template
- // or a class template partial specialization.
if (const TemplateSpecializationType *SpecType
= dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) {
+ // We are entering the context of the nested name specifier, so try to
+ // match the nested name specifier to either a primary class template
+ // or a class template partial specialization.
if (ClassTemplateDecl *ClassTemplate
= dyn_cast_or_null<ClassTemplateDecl>(
SpecType->getTemplateName().getAsTemplateDecl())) {
@@ -74,6 +74,10 @@
= ClassTemplate->findPartialSpecialization(ContextType))
return PartialSpec;
}
+ } else if (const RecordType *RecordT
+ = dyn_cast_or_null<RecordType>(NNS->getAsType())) {
+ // The nested name specifier refers to a member of a class template.
+ return RecordT->getDecl();
}
std::string NNSString;
@@ -260,17 +264,14 @@
const CXXScopeSpec &SS,
SourceLocation IdLoc,
SourceLocation CCLoc,
- IdentifierInfo &II) {
+ IdentifierInfo &II,
+ bool EnteringContext) {
NestedNameSpecifier *Prefix
= static_cast<NestedNameSpecifier *>(SS.getScopeRep());
- // If the prefix already refers to an unknown specialization, there
- // is no name lookup to perform. Just build the resulting
- // nested-name-specifier.
- if (Prefix && isUnknownSpecialization(SS))
- return NestedNameSpecifier::Create(Context, Prefix, &II);
-
- NamedDecl *SD = LookupParsedName(S, &SS, &II, LookupNestedNameSpecifierName);
+ NamedDecl *SD = LookupParsedName(S, &SS, &II, LookupNestedNameSpecifierName,
+ false, false, SourceLocation(),
+ EnteringContext);
if (SD) {
if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD))
@@ -303,13 +304,16 @@
// Fall through to produce an error: we found something that isn't
// a class or a namespace.
- }
+ } else if (SS.isSet() && isDependentScopeSpecifier(SS))
+ return NestedNameSpecifier::Create(Context, Prefix, &II);
// If we didn't find anything during our lookup, try again with
// ordinary name lookup, which can help us produce better error
// messages.
if (!SD)
- SD = LookupParsedName(S, &SS, &II, LookupOrdinaryName);
+ SD = LookupParsedName(S, &SS, &II, LookupOrdinaryName,
+ false, false, SourceLocation(),
+ EnteringContext);
unsigned DiagID;
if (SD)
DiagID = diag::err_expected_class_or_namespace;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 25 17:51:20 2009
@@ -72,7 +72,7 @@
// refer to a member of an unknown specialization.
if (SS && isUnknownSpecialization(*SS))
return 0;
-
+
LookupResult Result
= LookupParsedName(S, SS, &II, LookupOrdinaryName, false, false);
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Aug 25 17:51:20 2009
@@ -1116,7 +1116,7 @@
/// @param S The scope from which unqualified name lookup will
/// begin.
///
-/// @param SS An optional C++ scope-specified, e.g., "::N::M".
+/// @param SS An optional C++ scope-specifier, e.g., "::N::M".
///
/// @param Name The name of the entity that name lookup will
/// search for.
@@ -1125,49 +1125,56 @@
/// name lookup. At present, this is only used to produce diagnostics when
/// C library functions (like "malloc") are implicitly declared.
///
+/// @param EnteringContext Indicates whether we are going to enter the
+/// context of the scope-specifier SS (if present).
+///
/// @returns The result of qualified or unqualified name lookup.
Sema::LookupResult
Sema::LookupParsedName(Scope *S, const CXXScopeSpec *SS,
DeclarationName Name, LookupNameKind NameKind,
bool RedeclarationOnly, bool AllowBuiltinCreation,
- SourceLocation Loc) {
- if (SS && (SS->isSet() || SS->isInvalid())) {
- // If the scope specifier is invalid, don't even look for
+ SourceLocation Loc,
+ bool EnteringContext) {
+ if (SS && SS->isInvalid()) {
+ // When the scope specifier is invalid, don't even look for
// anything.
- if (SS->isInvalid())
- return LookupResult::CreateLookupResult(Context, 0);
-
- assert(!isUnknownSpecialization(*SS) && "Can't lookup dependent types");
-
- if (isDependentScopeSpecifier(*SS)) {
- // Determine whether we are looking into the current
- // instantiation.
- NestedNameSpecifier *NNS
- = static_cast<NestedNameSpecifier *>(SS->getScopeRep());
- CXXRecordDecl *Current = getCurrentInstantiationOf(NNS);
- assert(Current && "Bad dependent scope specifier");
+ return LookupResult::CreateLookupResult(Context, 0);
+ }
+
+ if (SS && SS->isSet()) {
+ if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) {
+ // We have resolved the scope specifier to a particular declaration
+ // contex, and will perform name lookup in that context.
- // We nested name specifier refers to the current instantiation,
- // so now we will look for a member of the current instantiation
- // (C++0x [temp.dep.type]).
- unsigned IDNS = getIdentifierNamespacesFromLookupNameKind(NameKind, true);
- DeclContext::lookup_iterator I, E;
- for (llvm::tie(I, E) = Current->lookup(Name); I != E; ++I)
- if (isAcceptableLookupResult(*I, NameKind, IDNS))
- return LookupResult::CreateLookupResult(Context, I, E);
+ if (DC->isDependentContext()) {
+ // If this is a dependent context, then we are looking for a member of
+ // the current instantiation. This is a narrow search that looks into
+ // just the described declaration context (C++0x [temp.dep.type]).
+ unsigned IDNS = getIdentifierNamespacesFromLookupNameKind(NameKind,
+ true);
+ DeclContext::lookup_iterator I, E;
+ for (llvm::tie(I, E) = DC->lookup(Name); I != E; ++I)
+ if (isAcceptableLookupResult(*I, NameKind, IDNS))
+ return LookupResult::CreateLookupResult(Context, I, E);
+ }
+
+ // Qualified name lookup into the named declaration context.
+ // The declaration context must be complete.
+ if (RequireCompleteDeclContext(*SS))
+ return LookupResult::CreateLookupResult(Context, 0);
+
+ return LookupQualifiedName(DC, Name, NameKind, RedeclarationOnly);
}
- if (RequireCompleteDeclContext(*SS))
- return LookupResult::CreateLookupResult(Context, 0);
-
- return LookupQualifiedName(computeDeclContext(*SS),
- Name, NameKind, RedeclarationOnly);
+ // We could not resolve the scope specified to a specific declaration
+ // context, which means that SS refers to an unknown specialization.
+ // Name lookup can't find anything in this case.
+ return LookupResult::CreateLookupResult(Context, 0);
}
- LookupResult result(LookupName(S, Name, NameKind, RedeclarationOnly,
- AllowBuiltinCreation, Loc));
-
- return(result);
+ // Perform unqualified name lookup starting in the given scope.
+ return LookupName(S, Name, NameKind, RedeclarationOnly, AllowBuiltinCreation,
+ Loc);
}
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Aug 25 17:51:20 2009
@@ -27,10 +27,19 @@
/// passed to indicate the C++ scope in which the identifier will be
/// found.
TemplateNameKind Sema::isTemplateName(const IdentifierInfo &II, Scope *S,
- TemplateTy &TemplateResult,
- const CXXScopeSpec *SS) {
- NamedDecl *IIDecl = LookupParsedName(S, SS, &II, LookupOrdinaryName);
-
+ const CXXScopeSpec *SS,
+ bool EnteringContext,
+ TemplateTy &TemplateResult) {
+ LookupResult Found = LookupParsedName(S, SS, &II, LookupOrdinaryName,
+ false, false, SourceLocation(),
+ EnteringContext);
+
+ // FIXME: Cope with ambiguous name-lookup results.
+ assert(!Found.isAmbiguous() &&
+ "Cannot handle template name-lookup ambiguities");
+
+ NamedDecl *IIDecl = Found;
+
TemplateNameKind TNK = TNK_Non_template;
TemplateDecl *Template = 0;
@@ -1116,7 +1125,7 @@
// "template" keyword is now permitted). We follow the C++0x
// rules, even in C++03 mode, retroactively applying the DR.
TemplateTy Template;
- TemplateNameKind TNK = isTemplateName(Name, 0, Template, &SS);
+ TemplateNameKind TNK = isTemplateName(Name, 0, &SS, false, Template);
if (TNK == TNK_Non_template) {
Diag(NameLoc, diag::err_template_kw_refers_to_non_template)
<< &Name;
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Aug 25 17:51:20 2009
@@ -4378,7 +4378,8 @@
SS.setScopeRep(Prefix);
return static_cast<NestedNameSpecifier *>(
SemaRef.ActOnCXXNestedNameSpecifier(0, SS, Range.getEnd(),
- Range.getEnd(), II));
+ Range.getEnd(), II,
+ false));
}
template<typename Derived>
@@ -4435,7 +4436,7 @@
SS.setRange(SourceRange(getDerived().getBaseLocation()));
SS.setScopeRep(Qualifier);
Sema::TemplateTy Template;
- TemplateNameKind TNK = SemaRef.isTemplateName(II, 0, Template, &SS);
+ TemplateNameKind TNK = SemaRef.isTemplateName(II, 0, &SS, false, Template);
if (TNK == TNK_Non_template) {
SemaRef.Diag(getDerived().getBaseLocation(),
diag::err_template_kw_refers_to_non_template)
Modified: cfe/trunk/test/SemaTemplate/dependent-type-identity.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-type-identity.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-type-identity.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-type-identity.cpp Tue Aug 25 17:51:20 2009
@@ -59,7 +59,7 @@
void f6(typename N::X2<U>::template apply<U> *);
void f6(typename N::X2<U>::template apply<T> *);
void f6(typename ::N::X2<type>::template apply<U_type> *); // expected-error{{redeclar}}
-
+
void f7(typename N::X2<T>::template apply<U> *); // expected-note{{previous}}
void f7(typename N::X2<U>::template apply<U> *);
void f7(typename N::X2<U>::template apply<T> *);
Modified: cfe/trunk/test/SemaTemplate/nested-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/nested-template.cpp?rev=80044&r1=80043&r2=80044&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/nested-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/nested-template.cpp Tue Aug 25 17:51:20 2009
@@ -1,5 +1,4 @@
// RUN: clang-cc -fsyntax-only -verify %s
-
class A;
class S {
@@ -25,6 +24,7 @@
T foo(U);
template<typename V> T bar(V);
+ template<typename V> T* bar(V);
};
};
@@ -35,9 +35,6 @@
void f(X, Y);
};
-#if 0
-// FIXME: These don't parse properly because we can't handle the template-name
-// "Inner0" or "Inner1" after the dependent type Outer<X>.
template<typename X>
template<typename Y>
void Outer<X>::Inner0<Y>::f(X, Y) {
@@ -66,4 +63,10 @@
X Outer<X>::Inner1<Y>::bar(Z) {
return X();
}
-#endif
\ No newline at end of file
+
+template<typename X>
+template<typename Y>
+template<typename Z>
+X* Outer<X>::Inner1<Y>::bar(Z) {
+ return 0;
+}
More information about the cfe-commits
mailing list