From bc84532e762a41141bd94037cd5d1133f234088e Mon Sep 17 00:00:00 2001 From: Francois Pichet Date: Wed, 17 Aug 2011 01:06:54 +0000 Subject: [PATCH] Add serialization support for ClassScopeFunctionSpecializationDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137799 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclBase.cpp | 3 +- lib/Serialization/ASTReaderDecl.cpp | 8 +++++ lib/Serialization/ASTWriterDecl.cpp | 10 +++++++ ...ms-function-specialization-class-scope.cpp | 13 +++++++++ ...x-ms-function-specialization-class-scope.h | 29 +++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/PCH/cxx-ms-function-specialization-class-scope.cpp create mode 100644 test/PCH/cxx-ms-function-specialization-class-scope.h diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 5e5ec93e17..ca3f5b563c 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -628,7 +628,8 @@ void Decl::CheckAccessDeclContext() const { isa(this) || // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have // AS_none as access specifier. - isa(this)) + isa(this) || + isa(this)) return; assert(Access != AS_none && diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 66316bc1e1..0c29b34b6f 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -123,6 +123,8 @@ namespace clang { ClassTemplateSpecializationDecl *D); void VisitClassTemplatePartialSpecializationDecl( ClassTemplatePartialSpecializationDecl *D); + void VisitClassScopeFunctionSpecializationDecl( + ClassScopeFunctionSpecializationDecl *D); void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); void VisitValueDecl(ValueDecl *VD); void VisitEnumConstantDecl(EnumConstantDecl *ECD); @@ -1215,6 +1217,12 @@ void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( } } +void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( + ClassScopeFunctionSpecializationDecl *D) { + VisitDecl(D); + D->Specialization = ReadDeclAs(Record, Idx); +} + void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { VisitRedeclarableTemplateDecl(D); diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 3e1a42c52d..efc1ea30ef 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -65,6 +65,8 @@ namespace clang { ClassTemplateSpecializationDecl *D); void VisitClassTemplatePartialSpecializationDecl( ClassTemplatePartialSpecializationDecl *D); + void VisitClassScopeFunctionSpecializationDecl( + ClassScopeFunctionSpecializationDecl *D); void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); void VisitValueDecl(ValueDecl *D); void VisitEnumConstantDecl(EnumConstantDecl *D); @@ -1109,6 +1111,14 @@ void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; } +void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl( + ClassScopeFunctionSpecializationDecl *D) { + VisitDecl(D); + Writer.AddDeclRef(D->getSpecialization(), Record); + Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION; +} + + void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { VisitRedeclarableTemplateDecl(D); diff --git a/test/PCH/cxx-ms-function-specialization-class-scope.cpp b/test/PCH/cxx-ms-function-specialization-class-scope.cpp new file mode 100644 index 0000000000..1803a11b96 --- /dev/null +++ b/test/PCH/cxx-ms-function-specialization-class-scope.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -x c++-header -emit-pch -o %t %S/cxx-ms-function-specialization-class-scope.h +// RUN: %clang_cc1 -fms-extensions -triple i386-unknown-unknown -include-pch %t -fsyntax-only -verify %s + + +void test2() +{ + B b(3); + char* ptr; + b.f(ptr); + b.f(99); + b.f(100); +} + diff --git a/test/PCH/cxx-ms-function-specialization-class-scope.h b/test/PCH/cxx-ms-function-specialization-class-scope.h new file mode 100644 index 0000000000..7668e73384 --- /dev/null +++ b/test/PCH/cxx-ms-function-specialization-class-scope.h @@ -0,0 +1,29 @@ + + + +template +class B { +public: + template + B(U p) { + } + template <> + B(int p) { // expected-warning{{explicit specialization of 'B' within class scope is a Microsoft extension}} + } + + template + void f(U p) { + T y = 9; + } + + + template <> + void f(int p) { // expected-warning{{explicit specialization of 'f' within class scope is a Microsoft extension}} + T a = 3; + } + + void f(int p) { + T a = 3; + } +}; + -- 2.40.0