[cfe-commits] r80366 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/using-decl-templates.cpp
Anders Carlsson
andersca at mac.com
Fri Aug 28 08:18:16 PDT 2009
Author: andersca
Date: Fri Aug 28 10:18:15 2009
New Revision: 80366
URL: http://llvm.org/viewvc/llvm-project?rev=80366&view=rev
Log:
Instantiate unresolved using declarations.
Added:
cfe/trunk/test/SemaCXX/using-decl-templates.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=80366&r1=80365&r2=80366&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Aug 28 10:18:15 2009
@@ -1610,7 +1610,7 @@
return TargetNestedNameDecl;
}
- /// isTypeName - Return true if using decl had 'typename'.
+ /// isTypeName - Return true if using decl has 'typename'.
bool isTypeName() const { return IsTypeName; }
static UsingDecl *Create(ASTContext &C, DeclContext *DC,
@@ -1651,6 +1651,23 @@
IsTypeName(IsTypeNameArg) { }
public:
+ /// \brief Returns the source range that covers the nested-name-specifier
+ /// preceding the namespace name.
+ SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
+
+ /// \brief Get target nested name declaration.
+ NestedNameSpecifier* getTargetNestedNameSpecifier() {
+ return TargetNestedNameSpecifier;
+ }
+
+ /// \brief Returns the source location of the target declaration name.
+ SourceLocation getTargetNameLocation() const { return TargetNameLocation; }
+
+ /// \brief Returns the source location of the target declaration name.
+ DeclarationName getTargetName() const { return TargetName; }
+
+ bool isTypeName() const { return IsTypeName; }
+
static UnresolvedUsingDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation UsingLoc,
SourceRange TargetNNR,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=80366&r1=80365&r2=80366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Aug 28 10:18:15 2009
@@ -2160,8 +2160,9 @@
<< NNS << RD->getDeclName();
return 0;
}
-
- LookupContext = cast<RecordType>(Ty)->getDecl();
+
+ QualType BaseTy = Context.getCanonicalType(QualType(Ty, 0));
+ LookupContext = BaseTy->getAs<RecordType>()->getDecl();
} else {
// C++0x N2914 [namespace.udecl]p8:
// A using-declaration for a class member shall be a member-declaration.
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=80366&r1=80365&r2=80366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Aug 28 10:18:15 2009
@@ -58,7 +58,8 @@
Decl *VisitClassTemplateDecl(ClassTemplateDecl *D);
Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
-
+ Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D);
+
// Base case. FIXME: Remove once we can instantiate everything.
Decl *VisitDecl(Decl *) {
assert(false && "Template instantiation of unknown declaration kind!");
@@ -740,6 +741,24 @@
return Inst;
}
+Decl *
+TemplateDeclInstantiator::VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D) {
+ NestedNameSpecifier *NNS =
+ SemaRef.SubstNestedNameSpecifier(D->getTargetNestedNameSpecifier(),
+ D->getTargetNestedNameRange(),
+ TemplateArgs);
+ if (!NNS)
+ return 0;
+
+ CXXScopeSpec SS;
+ SS.setRange(D->getTargetNestedNameRange());
+ SS.setScopeRep(NNS);
+
+ return SemaRef.BuildUsingDeclaration(D->getLocation(), SS,
+ D->getTargetNameLocation(),
+ D->getTargetName(), 0, D->isTypeName());
+}
+
Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner,
const TemplateArgumentList &TemplateArgs) {
TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
Added: cfe/trunk/test/SemaCXX/using-decl-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-templates.cpp?rev=80366&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/using-decl-templates.cpp (added)
+++ cfe/trunk/test/SemaCXX/using-decl-templates.cpp Fri Aug 28 10:18:15 2009
@@ -0,0 +1,16 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T> struct A {
+ void f() { }
+ struct N { };
+};
+
+template<typename T> struct B : A<T> {
+ using A<T>::f;
+ using A<T>::N;
+
+ using A<T>::foo; // expected-error{{no member named 'foo'}}
+ using A<double>::f; // expected-error{{using declaration refers into 'A<double>::', which is not a base class of 'B'}}
+};
+
+B<int> a; // expected-note{{in instantiation of template class 'struct B<int>' requested here}}
More information about the cfe-commits
mailing list