@@ -481,6 +481,17 @@ class ConstraintSatisfactionChecker {
481481 const MultiLevelTemplateArgumentList &MLTAL);
482482};
483483
484+ StringRef allocateStringFromConceptDiagnostic (const Sema &S,
485+ const PartialDiagnostic Diag) {
486+ SmallString<128 > DiagString;
487+ DiagString = " : " ;
488+ Diag.EmitToString (S.getDiagnostics (), DiagString);
489+ unsigned MessageSize = DiagString.size ();
490+ char *Mem = new (S.Context ) char [MessageSize];
491+ memcpy (Mem, DiagString.c_str (), MessageSize);
492+ return StringRef (Mem, MessageSize);
493+ }
494+
484495} // namespace
485496
486497ExprResult ConstraintSatisfactionChecker::EvaluateAtomicConstraint (
@@ -533,15 +544,10 @@ ExprResult ConstraintSatisfactionChecker::EvaluateAtomicConstraint(
533544 // just storing them as strings. We would still like, in the
534545 // future, to serialize the proper PartialDiagnostic as serializing
535546 // it as a string defeats the purpose of the diagnostic mechanism.
536- SmallString<128 > DiagString;
537- DiagString = " : " ;
538- SubstDiag.second .EmitToString (S.getDiagnostics (), DiagString);
539- unsigned MessageSize = DiagString.size ();
540- char *Mem = new (S.Context ) char [MessageSize];
541- memcpy (Mem, DiagString.c_str (), MessageSize);
542547 Satisfaction.Details .emplace_back (
543548 new (S.Context ) ConstraintSatisfaction::SubstitutionDiagnostic{
544- SubstDiag.first , StringRef (Mem, MessageSize)});
549+ SubstDiag.first ,
550+ allocateStringFromConceptDiagnostic (S, SubstDiag.second )});
545551 Satisfaction.IsSatisfied = false ;
546552 return ExprEmpty ();
547553 }
@@ -669,16 +675,10 @@ ExprResult ConstraintSatisfactionChecker::EvaluateSlow(
669675 Satisfaction.ContainsErrors = true ;
670676
671677 PartialDiagnostic Msg = S.PDiag (diag::note_constraint_references_error);
672- SmallString<128 > DiagString;
673- DiagString = " : " ;
674- Msg.EmitToString (S.getDiagnostics (), DiagString);
675- unsigned MessageSize = DiagString.size ();
676- char *Mem = new (S.Context ) char [MessageSize];
677- memcpy (Mem, DiagString.c_str (), MessageSize);
678678 Satisfaction.Details .emplace_back (
679679 new (S.Context ) ConstraintSatisfaction::SubstitutionDiagnostic{
680680 SubstitutedAtomicExpr.get ()->getBeginLoc (),
681- StringRef (Mem, MessageSize )});
681+ allocateStringFromConceptDiagnostic (S, Msg )});
682682 return SubstitutedAtomicExpr;
683683 }
684684
@@ -917,22 +917,17 @@ ExprResult ConstraintSatisfactionChecker::Evaluate(
917917 PartialDiagnosticAt SubstDiag{SourceLocation (),
918918 PartialDiagnostic::NullDiagnostic ()};
919919 Info.takeSFINAEDiagnostic (SubstDiag);
920- // FIXME: Concepts: This is an unfortunate consequence of there
920+ // FIXME: This is an unfortunate consequence of there
921921 // being no serialization code for PartialDiagnostics and the fact
922922 // that serializing them would likely take a lot more storage than
923923 // just storing them as strings. We would still like, in the
924924 // future, to serialize the proper PartialDiagnostic as serializing
925925 // it as a string defeats the purpose of the diagnostic mechanism.
926- SmallString<128 > DiagString;
927- DiagString = " : " ;
928- SubstDiag.second .EmitToString (S.getDiagnostics (), DiagString);
929- unsigned MessageSize = DiagString.size ();
930- char *Mem = new (S.Context ) char [MessageSize];
931- memcpy (Mem, DiagString.c_str (), MessageSize);
932926 Satisfaction.Details .insert (
933927 Satisfaction.Details .begin () + Size,
934928 new (S.Context ) ConstraintSatisfaction::SubstitutionDiagnostic{
935- SubstDiag.first , StringRef (Mem, MessageSize)});
929+ SubstDiag.first ,
930+ allocateStringFromConceptDiagnostic (S, SubstDiag.second )});
936931 return ExprError ();
937932 }
938933
0 commit comments