locale.c: fix format string for __LINE__ output (debugging) #21956
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On some platforms, building a -DDEBUGGING perl triggers the following compiler warnings:
This is because the code tries to format
__LINE__
with a varargs function using %"LINE_Tf".Things are slightly tricky here because in a varargs function, no type context is available, so the format string absolutely has to match the intrinsic type of each argument. The
__LINE__
macro expands to a simple (decimal) integer constant. According to C, such a constant has type int if its value fits, otherwise unsigned int if it fits, otherwise long int, etc. None of the *.c files in the perl distribution exceed 32767 lines (the minimum INT_MAX required by C), so even on ancient 16-bit systems, our__LINE__
will always be of type int.The %"LINE_Tf" format is designed to match a line_t argument, not int. (On some platforms, line_t is defined as unsigned long and incompatible with int for formatting purposes.) Therefore it is an error to use %"LINE_Tf" with
__LINE__
.One way to fix this is to convert the argument to match the format string:
... %"LINE_Tf" ...", (line_t)__LINE__
.The other way is to change the format string to match the (int) argument:
"... %d ...", __LINE__
.I chose option #2 because it is by far the most common way to output
__LINE__
elsewhere in the perl source.