From: Michal Privoznik <[email protected]> The aim of this rule is to capture the following pattern:
g_autofree const char *var = ...; The pattern is problematic, because it frees a const pointer. If written the old way, we'd get a compiler warning: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] Signed-off-by: Michal Privoznik <[email protected]> --- build-aux/syntax-check.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 4deaa70368..f605c9b0e3 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -389,6 +389,12 @@ sc_prohibit_unsigned_pid: halt='use signed type for pid values' \ $(_sc_search_regexp) +sc_prohibit_g_autofree_const: + @prohibit='\<g_auto(free|ptr)\>.* const.* \*[^*]' \ + halt='‘g_autofree’ discards ‘const’ qualifier from pointer target type' \ + $(_sc_search_regexp) + + # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \ # |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \ -- 2.52.0
