2222#include " UnwrappedLineFormatter.h"
2323#include " UsingDeclarationsSorter.h"
2424#include " clang/Tooling/Inclusions/HeaderIncludes.h"
25+
2526#include " llvm/ADT/Sequence.h"
27+ #include < limits>
2628
2729#define DEBUG_TYPE " format-formatter"
2830
@@ -777,7 +779,7 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
777779 IO.mapOptional (" Maximum" , signedMaximum);
778780 Space.Maximum = static_cast <unsigned >(signedMaximum);
779781
780- if (Space.Maximum != - 1u )
782+ if (Space.Maximum < std::numeric_limits< unsigned >:: max () )
781783 Space.Minimum = std::min (Space.Minimum , Space.Maximum );
782784 }
783785};
@@ -1672,7 +1674,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16721674 LLVMStyle.SpacesBeforeTrailingComments = 1 ;
16731675 LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
16741676 LLVMStyle.SpacesInContainerLiterals = true ;
1675- LLVMStyle.SpacesInLineCommentPrefix = {/* Minimum=*/ 1 , /* Maximum=*/ -1u };
1677+ LLVMStyle.SpacesInLineCommentPrefix = {
1678+ /* Minimum=*/ 1 , /* Maximum=*/ std::numeric_limits<unsigned >::max ()};
16761679 LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
16771680 LLVMStyle.SpacesInSquareBrackets = false ;
16781681 LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -3168,11 +3171,12 @@ static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start,
31683171// the index of the first of the duplicates as the others are going to be
31693172// removed. OffsetToEOL describes the cursor's position relative to the end of
31703173// its current line.
3171- // If `Cursor` is not on any #include, `Index` will be UINT_MAX.
3174+ // If `Cursor` is not on any #include, `Index` will be
3175+ // std::numeric_limits<unsigned>::max().
31723176static std::pair<unsigned , unsigned >
31733177FindCursorIndex (const ArrayRef<IncludeDirective> &Includes,
31743178 const ArrayRef<unsigned > &Indices, unsigned Cursor) {
3175- unsigned CursorIndex = UINT_MAX ;
3179+ unsigned CursorIndex = std::numeric_limits< unsigned >:: max () ;
31763180 unsigned OffsetToEOL = 0 ;
31773181 for (int i = 0 , e = Includes.size (); i != e; ++i) {
31783182 unsigned Start = Includes[Indices[i]].Offset ;
@@ -3440,11 +3444,12 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code,
34403444 return Replaces;
34413445}
34423446
3443- // Returns group number to use as a first order sort on imports. Gives UINT_MAX
3444- // if the import does not match any given groups.
3447+ // Returns group number to use as a first order sort on imports. Gives
3448+ // std::numeric_limits<unsigned>::max() if the import does not match any given
3449+ // groups.
34453450static unsigned findJavaImportGroup (const FormatStyle &Style,
34463451 StringRef ImportIdentifier) {
3447- unsigned LongestMatchIndex = UINT_MAX ;
3452+ unsigned LongestMatchIndex = std::numeric_limits< unsigned >:: max () ;
34483453 unsigned LongestMatchLength = 0 ;
34493454 for (unsigned I = 0 ; I < Style.JavaImportGroups .size (); I++) {
34503455 const std::string &GroupPrefix = Style.JavaImportGroups [I];
@@ -3673,13 +3678,15 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
36733678namespace {
36743679
36753680inline bool isHeaderInsertion (const tooling::Replacement &Replace) {
3676- return Replace.getOffset () == UINT_MAX && Replace.getLength () == 0 &&
3681+ return Replace.getOffset () == std::numeric_limits<unsigned >::max () &&
3682+ Replace.getLength () == 0 &&
36773683 tooling::HeaderIncludes::IncludeRegex.match (
36783684 Replace.getReplacementText ());
36793685}
36803686
36813687inline bool isHeaderDeletion (const tooling::Replacement &Replace) {
3682- return Replace.getOffset () == UINT_MAX && Replace.getLength () == 1 ;
3688+ return Replace.getOffset () == std::numeric_limits<unsigned >::max () &&
3689+ Replace.getLength () == 1 ;
36833690}
36843691
36853692// FIXME: insert empty lines between newly created blocks.
@@ -3699,7 +3706,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
36993706 consumeError (HeaderInsertions.add (R));
37003707 } else if (isHeaderDeletion (R)) {
37013708 HeadersToDelete.insert (R.getReplacementText ());
3702- } else if (R.getOffset () == UINT_MAX ) {
3709+ } else if (R.getOffset () == std::numeric_limits< unsigned >:: max () ) {
37033710 llvm::errs () << " Insertions other than header #include insertion are "
37043711 " not supported! "
37053712 << R.getReplacementText () << " \n " ;
0 commit comments