@@ -795,26 +795,27 @@ class RedeclarableTemplateDecl : public TemplateDecl,
795
795
EntryType *Entry, void *InsertPos);
796
796
797
797
struct CommonBase {
798
- CommonBase () : InstantiatedFromMember( nullptr , false ) {}
798
+ CommonBase () {}
799
799
800
800
// / The template from which this was most
801
801
// / directly instantiated (or null).
802
- // /
803
- // / The boolean value indicates whether this template
804
- // / was explicitly specialized.
805
- llvm::PointerIntPair<RedeclarableTemplateDecl *, 1 , bool >
806
- InstantiatedFromMember;
802
+ RedeclarableTemplateDecl *InstantiatedFromMember = nullptr ;
807
803
};
808
804
809
805
// / Pointer to the common data shared by all declarations of this
810
- // / template.
811
- mutable CommonBase *Common = nullptr ;
806
+ // / template, and a flag indicating if the template is a member
807
+ // / specialization.
808
+ mutable llvm::PointerIntPair<CommonBase *, 1 , bool > Common;
809
+
810
+ CommonBase *getCommonPtrInternal () const { return Common.getPointer (); }
812
811
813
812
// / Retrieves the "common" pointer shared by all (re-)declarations of
814
813
// / the same template. Calling this routine may implicitly allocate memory
815
814
// / for the common pointer.
816
815
CommonBase *getCommonPtr () const ;
817
816
817
+ void setCommonPtr (CommonBase *C) const { Common.setPointer (C); }
818
+
818
819
virtual CommonBase *newCommon (ASTContext &C) const = 0;
819
820
820
821
// Construct a template decl with name, parameters, and templated element.
@@ -855,15 +856,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
855
856
// / template<> template<typename T>
856
857
// / struct X<int>::Inner { /* ... */ };
857
858
// / \endcode
858
- bool isMemberSpecialization () const {
859
- return getCommonPtr ()->InstantiatedFromMember .getInt ();
860
- }
859
+ bool isMemberSpecialization () const { return Common.getInt (); }
861
860
862
861
// / Note that this member template is a specialization.
863
862
void setMemberSpecialization () {
864
- assert (getCommonPtr ()->InstantiatedFromMember .getPointer () &&
865
- " Only member templates can be member template specializations" );
866
- getCommonPtr ()->InstantiatedFromMember .setInt (true );
863
+ assert (!isMemberSpecialization () && " already a member specialization" );
864
+ Common.setInt (true );
867
865
}
868
866
869
867
// / Retrieve the member template from which this template was
@@ -903,12 +901,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
903
901
// / void X<T>::f(T, U);
904
902
// / \endcode
905
903
RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate () const {
906
- return getCommonPtr ()->InstantiatedFromMember . getPointer () ;
904
+ return getCommonPtr ()->InstantiatedFromMember ;
907
905
}
908
906
909
907
void setInstantiatedFromMemberTemplate (RedeclarableTemplateDecl *TD) {
910
- assert (!getCommonPtr ()->InstantiatedFromMember . getPointer () );
911
- getCommonPtr ()->InstantiatedFromMember . setPointer (TD) ;
908
+ assert (!getCommonPtr ()->InstantiatedFromMember );
909
+ getCommonPtr ()->InstantiatedFromMember = TD ;
912
910
}
913
911
914
912
// / Retrieve the "injected" template arguments that correspond to the
@@ -1958,13 +1956,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
1958
1956
// / specialization which was specialized by this.
1959
1957
llvm::PointerUnion<ClassTemplateDecl *,
1960
1958
ClassTemplatePartialSpecializationDecl *>
1961
- getSpecializedTemplateOrPartial () const {
1962
- if (const auto *PartialSpec =
1963
- SpecializedTemplate.dyn_cast <SpecializedPartialSpecialization *>())
1964
- return PartialSpec->PartialSpecialization ;
1965
-
1966
- return cast<ClassTemplateDecl *>(SpecializedTemplate);
1967
- }
1959
+ getSpecializedTemplateOrPartial () const ;
1968
1960
1969
1961
// / Retrieve the set of template arguments that should be used
1970
1962
// / to instantiate members of the class template or class template partial
@@ -1990,7 +1982,9 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
1990
1982
// / template arguments have been deduced.
1991
1983
void setInstantiationOf (ClassTemplatePartialSpecializationDecl *PartialSpec,
1992
1984
const TemplateArgumentList *TemplateArgs) {
1993
- assert (!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
1985
+ assert (!isa<ClassTemplatePartialSpecializationDecl>(this ) &&
1986
+ " A partial specialization cannot be instantiated from a template" );
1987
+ assert (!isa<SpecializedPartialSpecialization*>(SpecializedTemplate) &&
1994
1988
" Already set to a class template partial specialization!" );
1995
1989
auto *PS = new (getASTContext ()) SpecializedPartialSpecialization ();
1996
1990
PS->PartialSpecialization = PartialSpec;
@@ -2001,7 +1995,9 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
2001
1995
// / Note that this class template specialization is an instantiation
2002
1996
// / of the given class template.
2003
1997
void setInstantiationOf (ClassTemplateDecl *TemplDecl) {
2004
- assert (!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
1998
+ assert (!isa<ClassTemplatePartialSpecializationDecl>(this ) &&
1999
+ " A partial specialization cannot be instantiated from a template" );
2000
+ assert (!isa<SpecializedPartialSpecialization*>(SpecializedTemplate) &&
2005
2001
" Previously set to a class template partial specialization!" );
2006
2002
SpecializedTemplate = TemplDecl;
2007
2003
}
@@ -2194,18 +2190,11 @@ class ClassTemplatePartialSpecializationDecl
2194
2190
// / struct X<int>::Inner<T*> { /* ... */ };
2195
2191
// / \endcode
2196
2192
bool isMemberSpecialization () const {
2197
- const auto *First =
2198
- cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl ());
2199
- return First->InstantiatedFromMember .getInt ();
2193
+ return InstantiatedFromMember.getInt ();
2200
2194
}
2201
2195
2202
2196
// / Note that this member template is a specialization.
2203
- void setMemberSpecialization () {
2204
- auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl ());
2205
- assert (First->InstantiatedFromMember .getPointer () &&
2206
- " Only member templates can be member template specializations" );
2207
- return First->InstantiatedFromMember .setInt (true );
2208
- }
2197
+ void setMemberSpecialization () { return InstantiatedFromMember.setInt (true ); }
2209
2198
2210
2199
// / Retrieves the injected specialization type for this partial
2211
2200
// / specialization. This is not the same as the type-decl-type for
@@ -2275,8 +2264,6 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
2275
2264
return static_cast <Common *>(RedeclarableTemplateDecl::getCommonPtr ());
2276
2265
}
2277
2266
2278
- void setCommonPtr (Common *C) { RedeclarableTemplateDecl::Common = C; }
2279
-
2280
2267
public:
2281
2268
2282
2269
friend class ASTDeclReader ;
@@ -2727,13 +2714,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
2727
2714
// / Retrieve the variable template or variable template partial
2728
2715
// / specialization which was specialized by this.
2729
2716
llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2730
- getSpecializedTemplateOrPartial () const {
2731
- if (const auto *PartialSpec =
2732
- SpecializedTemplate.dyn_cast <SpecializedPartialSpecialization *>())
2733
- return PartialSpec->PartialSpecialization ;
2734
-
2735
- return cast<VarTemplateDecl *>(SpecializedTemplate);
2736
- }
2717
+ getSpecializedTemplateOrPartial () const ;
2737
2718
2738
2719
// / Retrieve the set of template arguments that should be used
2739
2720
// / to instantiate the initializer of the variable template or variable
@@ -2759,6 +2740,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
2759
2740
// / template arguments have been deduced.
2760
2741
void setInstantiationOf (VarTemplatePartialSpecializationDecl *PartialSpec,
2761
2742
const TemplateArgumentList *TemplateArgs) {
2743
+ assert (!isa<VarTemplatePartialSpecializationDecl>(this ) &&
2744
+ " A partial specialization cannot be instantiated from a template" );
2762
2745
assert (!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2763
2746
" Already set to a variable template partial specialization!" );
2764
2747
auto *PS = new (getASTContext ()) SpecializedPartialSpecialization ();
@@ -2770,6 +2753,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
2770
2753
// / Note that this variable template specialization is an instantiation
2771
2754
// / of the given variable template.
2772
2755
void setInstantiationOf (VarTemplateDecl *TemplDecl) {
2756
+ assert (!isa<VarTemplatePartialSpecializationDecl>(this ) &&
2757
+ " A partial specialization cannot be instantiated from a template" );
2773
2758
assert (!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2774
2759
" Previously set to a variable template partial specialization!" );
2775
2760
SpecializedTemplate = TemplDecl;
@@ -2960,18 +2945,11 @@ class VarTemplatePartialSpecializationDecl
2960
2945
// / U* X<int>::Inner<T*> = (T*)(0) + 1;
2961
2946
// / \endcode
2962
2947
bool isMemberSpecialization () const {
2963
- const auto *First =
2964
- cast<VarTemplatePartialSpecializationDecl>(getFirstDecl ());
2965
- return First->InstantiatedFromMember .getInt ();
2948
+ return InstantiatedFromMember.getInt ();
2966
2949
}
2967
2950
2968
2951
// / Note that this member template is a specialization.
2969
- void setMemberSpecialization () {
2970
- auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl ());
2971
- assert (First->InstantiatedFromMember .getPointer () &&
2972
- " Only member templates can be member template specializations" );
2973
- return First->InstantiatedFromMember .setInt (true );
2974
- }
2952
+ void setMemberSpecialization () { return InstantiatedFromMember.setInt (true ); }
2975
2953
2976
2954
SourceRange getSourceRange () const override LLVM_READONLY;
2977
2955
@@ -3142,6 +3120,9 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
3142
3120
return makeSpecIterator (getSpecializations (), true );
3143
3121
}
3144
3122
3123
+ // / Merge \p Prev with our RedeclarableTemplateDecl::Common.
3124
+ void mergePrevDecl (VarTemplateDecl *Prev);
3125
+
3145
3126
// Implement isa/cast/dyncast support
3146
3127
static bool classof (const Decl *D) { return classofKind (D->getKind ()); }
3147
3128
static bool classofKind (Kind K) { return K == VarTemplate; }
0 commit comments