@@ -654,11 +654,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
654
654
// / \param DiagID A member of the @c diag::kind enum.
655
655
// / \param Loc Represents the source location associated with the diagnostic,
656
656
// / which can be an invalid location if no position information is available.
657
- // / \param Val A string that represents the value that triggered
658
- // / this diagnostic. If given, this value will be emitted as "=value"
659
- // / after the flag name.
660
- inline DiagnosticBuilder Report (SourceLocation Loc, unsigned DiagID,
661
- StringRef Val);
662
657
inline DiagnosticBuilder Report (SourceLocation Loc, unsigned DiagID);
663
658
inline DiagnosticBuilder Report (unsigned DiagID);
664
659
@@ -694,9 +689,12 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
694
689
// / \brief Clear out the current diagnostic.
695
690
void Clear () { CurDiagID = ~0U ; }
696
691
697
- // / \brief Return the overridden name for this diagnostic flag.
692
+ // / \brief Return the value associated to this diagnostic flag.
698
693
StringRef getFlagNameValue () const { return StringRef (FlagNameValue); }
699
694
695
+ // / \brief Set the value associated to this diagnostic flag.
696
+ void setFlagNameValue (StringRef V) { FlagNameValue = V; }
697
+
700
698
private:
701
699
// / \brief Report the delayed diagnostic.
702
700
void ReportDelayed ();
@@ -1010,8 +1008,25 @@ class DiagnosticBuilder {
1010
1008
bool hasMaxFixItHints () const {
1011
1009
return NumFixits == DiagnosticsEngine::MaxFixItHints;
1012
1010
}
1011
+
1012
+ void addFlagValue (StringRef V) const { DiagObj->setFlagNameValue (V); }
1013
+ };
1014
+
1015
+ struct AddFlagValue {
1016
+ explicit AddFlagValue (StringRef V) : Val(V) {}
1017
+ StringRef Val;
1013
1018
};
1014
1019
1020
+ // / \brief Register a value for the flag in the current diagnostic. This
1021
+ // / value will be shown as the suffix "=value" after the flag name. It is
1022
+ // / useful in cases where the diagnostic flag accepts values (e.g.,
1023
+ // / -Rpass or -Wframe-larger-than).
1024
+ inline const DiagnosticBuilder &operator <<(const DiagnosticBuilder &DB,
1025
+ const AddFlagValue V) {
1026
+ DB.addFlagValue (V.Val );
1027
+ return DB;
1028
+ }
1029
+
1015
1030
inline const DiagnosticBuilder &operator <<(const DiagnosticBuilder &DB,
1016
1031
StringRef S) {
1017
1032
DB.AddString (S);
@@ -1100,22 +1115,17 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1100
1115
return DB;
1101
1116
}
1102
1117
1103
- inline DiagnosticBuilder
1104
- DiagnosticsEngine::Report (SourceLocation Loc, unsigned DiagID, StringRef Val ) {
1118
+ inline DiagnosticBuilder DiagnosticsEngine::Report (SourceLocation Loc,
1119
+ unsigned DiagID ) {
1105
1120
assert (CurDiagID == ~0U && " Multiple diagnostics in flight at once!" );
1106
1121
CurDiagLoc = Loc;
1107
1122
CurDiagID = DiagID;
1108
- FlagNameValue = Val. str ();
1123
+ FlagNameValue. clear ();
1109
1124
return DiagnosticBuilder (this );
1110
1125
}
1111
1126
1112
- inline DiagnosticBuilder DiagnosticsEngine::Report (SourceLocation Loc,
1113
- unsigned DiagID) {
1114
- return Report (Loc, DiagID, " " );
1115
- }
1116
-
1117
1127
inline DiagnosticBuilder DiagnosticsEngine::Report (unsigned DiagID) {
1118
- return Report (SourceLocation (), DiagID, " " );
1128
+ return Report (SourceLocation (), DiagID);
1119
1129
}
1120
1130
1121
1131
// ===----------------------------------------------------------------------===//
0 commit comments