From a038c1dcface5a404d540a0d0688962cbe656af9 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 3 Jul 2010 07:57:53 +0000 Subject: [PATCH] When setting the anonymous namespace at PCH reading, it may still be initializing so avoid the invariant checks at NamespaceDecl::setAnonymousNamespace(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107566 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 3 +++ lib/Frontend/PCHReaderDecl.cpp | 8 ++------ test/PCH/cxx-namespaces.cpp | 10 ++++++++++ test/PCH/cxx-namespaces.h | 7 +++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 test/PCH/cxx-namespaces.cpp create mode 100644 test/PCH/cxx-namespaces.h diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index da7ad1d217..c35a399263 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -344,6 +344,9 @@ public: static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + friend class PCHDeclReader; + friend class PCHDeclWriter; }; /// ValueDecl - Represent the declaration of a variable (in which case it is diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index 8e0d635508..9de002b0e6 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -564,13 +564,9 @@ void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { D->setNextNamespace( cast_or_null(Reader.GetDecl(Record[Idx++]))); - // Only read one reference--the original or anonymous namespace. bool IsOriginal = Record[Idx++]; - if (IsOriginal) - D->setAnonymousNamespace( - cast_or_null(Reader.GetDecl(Record[Idx++]))); - else - D->setOriginalNamespace( + D->OrigOrAnonNamespace.setInt(IsOriginal); + D->OrigOrAnonNamespace.setPointer( cast_or_null(Reader.GetDecl(Record[Idx++]))); } diff --git a/test/PCH/cxx-namespaces.cpp b/test/PCH/cxx-namespaces.cpp new file mode 100644 index 0000000000..0fd3de7f6c --- /dev/null +++ b/test/PCH/cxx-namespaces.cpp @@ -0,0 +1,10 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-namespaces.h -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-namespaces.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s + +void m() { + N::x = 0; +} diff --git a/test/PCH/cxx-namespaces.h b/test/PCH/cxx-namespaces.h new file mode 100644 index 0000000000..f3389533d0 --- /dev/null +++ b/test/PCH/cxx-namespaces.h @@ -0,0 +1,7 @@ +// Header for PCH test cxx-namespaces.cpp + +namespace N { + namespace { + int x; + } +} -- 2.40.0