Draft
Conversation
The GCC warning [`-Wsuggest-attribute=attribute_name`][1] can be used to suggest to apply attributes to functions. Enable it to find all candidates for the `format` attribute, and apply it. A few notes: - The `wprintf` archetype for the format attribute is not supported; - attributes are applied to function _names_, not _types_, thus it is not possible to apply the format attribute inside the `Logger` typedef, thus the macro. As this change is constrained to ocamltest, I believe it is not too invasive. [1]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wsuggest-attribute_003d
Use GCC `-Wsuggest-attribute=noreturn` warning to find functions possibly missing a `noreturn` attribute. Applying the `noreturn` attribute allows removing the placeholder returns. The GCC manual has this line about the `noreturn` attribute: > It does not make sense for a `noreturn` function to have a return > type other than `void`. Change the return type of some primitives when they always throw an exception.
> You may optionally specify attribute names with `__` preceding and > following the name. This allows you to use them in header files > without being concerned about a possible macro of the same name. For > example, you may use the attribute name `__noreturn__` instead of > noreturn. https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
70b843d to
524a150
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The GCC
-Wsuggest-attribute=attribute_namewarning warns for cases where adding an attribute may be beneficial. I've used it for theformat,noreturn,malloc, andreturns_nonnull.I've also tried with
pureandconstbut found out that these mostly apply to primitives, thus adding the attribute brings no benefit.About format:
The GCC warning
-Wsuggest-attribute=attribute_namecan be used to suggest to apply attributes to functions. Enable it to find all candidates for theformatattribute, and apply it.A few notes:
wprintfarchetype for the format attribute is not supported;Loggertypedef, thus the macro. As this change is constrained to ocamltest, I believe it is not too invasive.About noreturn:
Use GCC
-Wsuggest-attribute=noreturnwarning to find functions possibly missing anoreturnattribute. Applying thenoreturnattribute allows removing the placeholder returns.The GCC manual has this line about the
noreturnattribute:Change the return type of some primitives when they always throw an exception.
About surround attribute names with
__in headers:The GCC docs about attribute syntax suggests this: