Files
llvm-project/llvm/lib/Support/NativeFormatting.cpp
Konrad Kleine bcd8e64884 [llvm][Support] formatv: non-negative-plus for integral numbers (#185008)
The older `format()` allows you to print a `+` sign for non-negative    
integral numbers upon request.                                          
                                                                        
Examples:                                                               
                                                                        
```c++                                                                  
format("%+d", 255); // -> "+255"                                        
format("%+d", -12); // -> "-12"                                         
```                                                                     
                                                                        
This change adds the ability to do the same with `formatv()`:           
                                                                        
```c++                                                                  
formatv("{0:+d}", 255); // -> "+255"                                    
formatv("{0:+d}", -12); // -> "-12"                                     
```                                                                     
                                                                        
The default behaviour is not changed. That means, for a format specifier
like "{0:d}" we still print the positive integer without a "+" prefix.  
                                                                        
The special case of "+0" is exactly like it is handled with `format()`: 
                                                                        
```c++                                                                  
format("%+d", 0); // -> "+0"                                            
```                                                                     
                                                                        
This work is related to #35980.
2026-03-12 13:02:14 +01:00

8.1 KiB