Support PCH emitting/reading of using declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106404 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h
index 2caba65..b1b8d05 100644
--- a/include/clang/AST/DeclCXX.h
+++ b/include/clang/AST/DeclCXX.h
@@ -1854,9 +1854,12 @@
UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
NamedDecl *Target)
- : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
+ : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
Underlying(Target), Using(Using) {
- IdentifierNamespace = Target->getIdentifierNamespace();
+ if (Target) {
+ setDeclName(Target->getDeclName());
+ IdentifierNamespace = Target->getIdentifierNamespace();
+ }
setImplicit();
}
@@ -1873,7 +1876,11 @@
/// \brief Sets the underlying declaration which has been brought into the
/// local scope.
- void setTargetDecl(NamedDecl* ND) { Underlying = ND; }
+ void setTargetDecl(NamedDecl* ND) {
+ assert(ND && "Target decl is null!");
+ Underlying = ND;
+ IdentifierNamespace = ND->getIdentifierNamespace();
+ }
/// \brief Gets the using declaration to which this declaration is tied.
UsingDecl *getUsingDecl() const { return Using; }
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 3fc159a..2968aea 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -76,8 +76,8 @@
void VisitClassTemplateDecl(ClassTemplateDecl *D);
void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
- void VisitUsing(UsingDecl *D);
- void VisitUsingShadow(UsingShadowDecl *D);
+ void VisitUsingDecl(UsingDecl *D);
+ void VisitUsingShadowDecl(UsingShadowDecl *D);
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
void VisitAccessSpecDecl(AccessSpecDecl *D);
@@ -505,7 +505,7 @@
D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
}
-void PCHDeclReader::VisitUsing(UsingDecl *D) {
+void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
VisitNamedDecl(D);
D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
@@ -521,7 +521,7 @@
D->setTypeName(Record[Idx++]);
}
-void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
+void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
VisitNamedDecl(D);
D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index a704d67..4ea764d 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -77,8 +77,8 @@
void VisitClassTemplateDecl(ClassTemplateDecl *D);
void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
- void VisitUsing(UsingDecl *D);
- void VisitUsingShadow(UsingShadowDecl *D);
+ void VisitUsingDecl(UsingDecl *D);
+ void VisitUsingShadowDecl(UsingShadowDecl *D);
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
void VisitAccessSpecDecl(AccessSpecDecl *D);
@@ -521,7 +521,7 @@
Code = pch::DECL_NAMESPACE_ALIAS;
}
-void PCHDeclWriter::VisitUsing(UsingDecl *D) {
+void PCHDeclWriter::VisitUsingDecl(UsingDecl *D) {
VisitNamedDecl(D);
Writer.AddSourceRange(D->getNestedNameRange(), Record);
Writer.AddSourceLocation(D->getUsingLocation(), Record);
@@ -534,7 +534,7 @@
Code = pch::DECL_USING;
}
-void PCHDeclWriter::VisitUsingShadow(UsingShadowDecl *D) {
+void PCHDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
VisitNamedDecl(D);
Writer.AddDeclRef(D->getTargetDecl(), Record);
Writer.AddDeclRef(D->getUsingDecl(), Record);
diff --git a/test/PCH/cxx-using.cpp b/test/PCH/cxx-using.cpp
new file mode 100644
index 0000000..2ca7dad
--- /dev/null
+++ b/test/PCH/cxx-using.cpp
@@ -0,0 +1,15 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-using.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-using.h
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
+
+void m() {
+ D s; // expected-note {{candidate function}}
+ s.f(); // expected-error {{no matching member}}
+}
+
+
+
+// expected-note {{candidate function}}
diff --git a/test/PCH/cxx-using.h b/test/PCH/cxx-using.h
new file mode 100644
index 0000000..572cea2
--- /dev/null
+++ b/test/PCH/cxx-using.h
@@ -0,0 +1,16 @@
+// Header for PCH test cxx-using.cpp
+
+
+
+
+
+
+struct B {
+ void f(char c);
+};
+
+struct D : B
+{
+ using B::f;
+ void f(int);
+};