@@ -781,15 +781,11 @@ class RedeclarableTemplateDecl : public TemplateDecl,
781
781
EntryType *Entry, void *InsertPos);
782
782
783
783
struct CommonBase {
784
- CommonBase () : InstantiatedFromMember( nullptr , false ) {}
784
+ CommonBase () {}
785
785
786
786
// / The template from which this was most
787
787
// / directly instantiated (or null).
788
- // /
789
- // / The boolean value indicates whether this template
790
- // / was explicitly specialized.
791
- llvm::PointerIntPair<RedeclarableTemplateDecl*, 1 , bool >
792
- InstantiatedFromMember;
788
+ RedeclarableTemplateDecl *InstantiatedFromMember = nullptr ;
793
789
794
790
// / If non-null, points to an array of specializations (including
795
791
// / partial specializations) known only by their external declaration IDs.
@@ -809,14 +805,19 @@ class RedeclarableTemplateDecl : public TemplateDecl,
809
805
};
810
806
811
807
// / Pointer to the common data shared by all declarations of this
812
- // / template.
813
- mutable CommonBase *Common = nullptr ;
808
+ // / template, and a flag indicating if the template is a member
809
+ // / specialization.
810
+ mutable llvm::PointerIntPair<CommonBase *, 1 , bool > Common;
811
+
812
+ CommonBase *getCommonPtrInternal () const { return Common.getPointer (); }
814
813
815
814
// / Retrieves the "common" pointer shared by all (re-)declarations of
816
815
// / the same template. Calling this routine may implicitly allocate memory
817
816
// / for the common pointer.
818
817
CommonBase *getCommonPtr () const ;
819
818
819
+ void setCommonPtr (CommonBase *C) const { Common.setPointer (C); }
820
+
820
821
virtual CommonBase *newCommon (ASTContext &C) const = 0;
821
822
822
823
// Construct a template decl with name, parameters, and templated element.
@@ -857,15 +858,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
857
858
// / template<> template<typename T>
858
859
// / struct X<int>::Inner { /* ... */ };
859
860
// / \endcode
860
- bool isMemberSpecialization () const {
861
- return getCommonPtr ()->InstantiatedFromMember .getInt ();
862
- }
861
+ bool isMemberSpecialization () const { return Common.getInt (); }
863
862
864
863
// / Note that this member template is a specialization.
865
864
void setMemberSpecialization () {
866
- assert (getCommonPtr ()->InstantiatedFromMember .getPointer () &&
867
- " Only member templates can be member template specializations" );
868
- getCommonPtr ()->InstantiatedFromMember .setInt (true );
865
+ assert (!isMemberSpecialization () && " already a member specialization" );
866
+ Common.setInt (true );
869
867
}
870
868
871
869
// / Retrieve the member template from which this template was
@@ -905,12 +903,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
905
903
// / void X<T>::f(T, U);
906
904
// / \endcode
907
905
RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate () const {
908
- return getCommonPtr ()->InstantiatedFromMember . getPointer () ;
906
+ return getCommonPtr ()->InstantiatedFromMember ;
909
907
}
910
908
911
909
void setInstantiatedFromMemberTemplate (RedeclarableTemplateDecl *TD) {
912
- assert (!getCommonPtr ()->InstantiatedFromMember . getPointer () );
913
- getCommonPtr ()->InstantiatedFromMember . setPointer (TD) ;
910
+ assert (!getCommonPtr ()->InstantiatedFromMember );
911
+ getCommonPtr ()->InstantiatedFromMember = TD ;
914
912
}
915
913
916
914
// / Retrieve the "injected" template arguments that correspond to the
@@ -1989,6 +1987,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
1989
1987
// / template arguments have been deduced.
1990
1988
void setInstantiationOf (ClassTemplatePartialSpecializationDecl *PartialSpec,
1991
1989
const TemplateArgumentList *TemplateArgs) {
1990
+ assert (!isa<ClassTemplatePartialSpecializationDecl>(this ) &&
1991
+ " A partial specialization cannot be instantiated from a template" );
1992
1992
assert (!SpecializedTemplate.is <SpecializedPartialSpecialization*>() &&
1993
1993
" Already set to a class template partial specialization!" );
1994
1994
auto *PS = new (getASTContext ()) SpecializedPartialSpecialization ();
@@ -2000,6 +2000,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
2000
2000
// / Note that this class template specialization is an instantiation
2001
2001
// / of the given class template.
2002
2002
void setInstantiationOf (ClassTemplateDecl *TemplDecl) {
2003
+ assert (!isa<ClassTemplatePartialSpecializationDecl>(this ) &&
2004
+ " A partial specialization cannot be instantiated from a template" );
2003
2005
assert (!SpecializedTemplate.is <SpecializedPartialSpecialization*>() &&
2004
2006
" Previously set to a class template partial specialization!" );
2005
2007
SpecializedTemplate = TemplDecl;
@@ -2187,18 +2189,11 @@ class ClassTemplatePartialSpecializationDecl
2187
2189
// / struct X<int>::Inner<T*> { /* ... */ };
2188
2190
// / \endcode
2189
2191
bool isMemberSpecialization () const {
2190
- const auto *First =
2191
- cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl ());
2192
- return First->InstantiatedFromMember .getInt ();
2192
+ return InstantiatedFromMember.getInt ();
2193
2193
}
2194
2194
2195
2195
// / Note that this member template is a specialization.
2196
- void setMemberSpecialization () {
2197
- auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl ());
2198
- assert (First->InstantiatedFromMember .getPointer () &&
2199
- " Only member templates can be member template specializations" );
2200
- return First->InstantiatedFromMember .setInt (true );
2201
- }
2196
+ void setMemberSpecialization () { return InstantiatedFromMember.setInt (true ); }
2202
2197
2203
2198
// / Retrieves the injected specialization type for this partial
2204
2199
// / specialization. This is not the same as the type-decl-type for
@@ -2268,10 +2263,6 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
2268
2263
return static_cast <Common *>(RedeclarableTemplateDecl::getCommonPtr ());
2269
2264
}
2270
2265
2271
- void setCommonPtr (Common *C) {
2272
- RedeclarableTemplateDecl::Common = C;
2273
- }
2274
-
2275
2266
public:
2276
2267
2277
2268
friend class ASTDeclReader ;
@@ -2754,6 +2745,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
2754
2745
// / template arguments have been deduced.
2755
2746
void setInstantiationOf (VarTemplatePartialSpecializationDecl *PartialSpec,
2756
2747
const TemplateArgumentList *TemplateArgs) {
2748
+ assert (!isa<VarTemplatePartialSpecializationDecl>(this ) &&
2749
+ " A partial specialization cannot be instantiated from a template" );
2757
2750
assert (!SpecializedTemplate.is <SpecializedPartialSpecialization *>() &&
2758
2751
" Already set to a variable template partial specialization!" );
2759
2752
auto *PS = new (getASTContext ()) SpecializedPartialSpecialization ();
@@ -2765,6 +2758,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
2765
2758
// / Note that this variable template specialization is an instantiation
2766
2759
// / of the given variable template.
2767
2760
void setInstantiationOf (VarTemplateDecl *TemplDecl) {
2761
+ assert (!isa<VarTemplatePartialSpecializationDecl>(this ) &&
2762
+ " A partial specialization cannot be instantiated from a template" );
2768
2763
assert (!SpecializedTemplate.is <SpecializedPartialSpecialization *>() &&
2769
2764
" Previously set to a variable template partial specialization!" );
2770
2765
SpecializedTemplate = TemplDecl;
@@ -2949,18 +2944,11 @@ class VarTemplatePartialSpecializationDecl
2949
2944
// / U* X<int>::Inner<T*> = (T*)(0) + 1;
2950
2945
// / \endcode
2951
2946
bool isMemberSpecialization () const {
2952
- const auto *First =
2953
- cast<VarTemplatePartialSpecializationDecl>(getFirstDecl ());
2954
- return First->InstantiatedFromMember .getInt ();
2947
+ return InstantiatedFromMember.getInt ();
2955
2948
}
2956
2949
2957
2950
// / Note that this member template is a specialization.
2958
- void setMemberSpecialization () {
2959
- auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl ());
2960
- assert (First->InstantiatedFromMember .getPointer () &&
2961
- " Only member templates can be member template specializations" );
2962
- return First->InstantiatedFromMember .setInt (true );
2963
- }
2951
+ void setMemberSpecialization () { return InstantiatedFromMember.setInt (true ); }
2964
2952
2965
2953
SourceRange getSourceRange () const override LLVM_READONLY;
2966
2954
0 commit comments