@@ -785,6 +785,12 @@ void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
785
785
E->setRParenLoc (readSourceLocation ());
786
786
}
787
787
788
+ static StringRef saveStrToCtx (const std::string &S, ASTContext &Ctx) {
789
+ char *Buf = new (Ctx) char [S.size ()];
790
+ std::copy (S.begin (), S.end (), Buf);
791
+ return StringRef (Buf, S.size ());
792
+ }
793
+
788
794
static ConstraintSatisfaction
789
795
readConstraintSatisfaction (ASTRecordReader &Record) {
790
796
ConstraintSatisfaction Satisfaction;
@@ -795,14 +801,13 @@ readConstraintSatisfaction(ASTRecordReader &Record) {
795
801
for (unsigned i = 0 ; i != NumDetailRecords; ++i) {
796
802
if (/* IsDiagnostic */ Record.readInt ()) {
797
803
SourceLocation DiagLocation = Record.readSourceLocation ();
798
- std::string DiagMessage = Record.readString ();
799
- char *DBuf = new (Record.getContext ()) char [DiagMessage.size ()];
800
- std::copy (DiagMessage.begin (), DiagMessage.end (), DBuf);
804
+ StringRef DiagMessage =
805
+ saveStrToCtx (Record.readString (), Record.getContext ());
801
806
802
807
Satisfaction.Details .emplace_back (
803
808
new (Record.getContext ())
804
809
ConstraintSatisfaction::SubstitutionDiagnostic (DiagLocation,
805
- StringRef (DBuf, DiagMessage. size ()) ));
810
+ DiagMessage));
806
811
} else
807
812
Satisfaction.Details .emplace_back (Record.readExpr ());
808
813
}
@@ -823,19 +828,16 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
823
828
824
829
static concepts::Requirement::SubstitutionDiagnostic *
825
830
readSubstitutionDiagnostic (ASTRecordReader &Record) {
826
- std::string SubstitutedEntity = Record.readString ();
827
- char *SBuf = new (Record.getContext ()) char [SubstitutedEntity.size ()];
828
- std::copy (SubstitutedEntity.begin (), SubstitutedEntity.end (), SBuf);
831
+ StringRef SubstitutedEntity =
832
+ saveStrToCtx (Record.readString (), Record.getContext ());
829
833
830
834
SourceLocation DiagLoc = Record.readSourceLocation ();
831
- std::string DiagMessage = Record.readString ();
832
- char *DBuf = new (Record.getContext ()) char [DiagMessage.size ()];
833
- std::copy (DiagMessage.begin (), DiagMessage.end (), DBuf);
835
+ StringRef DiagMessage =
836
+ saveStrToCtx (Record.readString (), Record.getContext ());
834
837
835
838
return new (Record.getContext ())
836
- concepts::Requirement::SubstitutionDiagnostic{
837
- StringRef (SBuf, SubstitutedEntity.size ()), DiagLoc,
838
- StringRef (DBuf, DiagMessage.size ())};
839
+ concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
840
+ DiagMessage};
839
841
}
840
842
841
843
void ASTStmtReader::VisitRequiresExpr (RequiresExpr *E) {
0 commit comments