Skip to content

Fix #15179 (gtk.cfg: Complete and sort G_DEFINE_* list) - #8991

Merged
danmar merged 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:add-defines
Nov 6, 2026
Merged

danmar merged 1 commit into
cppcheck-opensource:mainfrom
Tamaranch:add-defines

Conversation

@Tamaranch

Copy link
Copy Markdown
Contributor

Added:
G_DEFINE_ENUM_TYPE
G_DEFINE_ENUM_VALUE
G_DEFINE_EXTENDED_ERROR
G_DEFINE_FLAGS_TYPE
G_DEFINE_POINTER_TYPE
G_DEFINE_POINTER_TYPE_WITH_CODE

@chrchr-github

Copy link
Copy Markdown
Collaborator

FYI there is this ticket regarding G_DEFINE_TYPE: https://trac.cppcheck.net/ticket/10890

@Tamaranch

Copy link
Copy Markdown
Contributor Author

FYI there is this ticket regarding G_DEFINE_TYPE: https://trac.cppcheck.net/ticket/10890

I've never seen warnings like these when running cppcheck on the Xfce codebase (which makes extensive use of G_DEFINE_TYPE). I'm inclined to believe that the problem stems from the code in question, which is using this macro incorrectly.

@chrchr-github

Copy link
Copy Markdown
Collaborator

Can you add test code using (some of) the new macros in gtk.c?

@Tamaranch
Tamaranch force-pushed the add-defines branch 4 times, most recently from c855854 to 977dcde Compare November 3, 2026 13:41

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no correctness problems. The reordering keeps every existing G_DEFINE_* define unchanged: I compared the sorted name lists of base and PR, and the only difference is the six new defines. The updated test/cfg/gtk.c passes, and it does exercise the new G_DEFINE_ENUM_TYPE, G_DEFINE_FLAGS_TYPE and G_DEFINE_ENUM_VALUE defines: with the base gtk.cfg it fails with unknownMacro.

There are two minor points, neither a blocker:

  • G_DEFINE_EXTENDED_ERROR, G_DEFINE_POINTER_TYPE and G_DEFINE_POINTER_TYPE_WITH_CODE have no test code in gtk.c.
  • Because G_DEFINE_EXTENDED_ERROR expands to nothing, the user's <error_type>_private_init/_copy/_clear functions get unusedFunction with --enable=all. G_DEFINE_TYPE already does the same thing to *_class_init/*_init, so this matches the existing approach.

Testing

  • Built cppcheck from pr/.
  • Ran the gtk.c cfg test with the options from test/cfg/runtests.sh (--check-library --platform=unix64 --enable=style,information --inconclusive --force --check-level=exhaustive --inline-suppr --debug-warnings --suppress=checkersReport --library=gtk test/cfg/gtk.c): no output, exit code 0. There is no pkg-config or GTK in the container, so the compiler syntax check of gtk.c was skipped.
  • Ran the same check on the PR's gtk.c with --library=../base/cfg/gtk.cfg. It fails with gtk.c:684: unknownMacro ... G_DEFINE_ENUM_TYPE, so the new test covers the change.
  • Compared the sorted G_DEFINE_* names in base and PR gtk.cfg: the only difference is the six added defines, so none was lost in the reorder.
  • Wrote a scratch file that uses G_DEFINE_EXTENDED_ERROR(MyError, my_error) with static my_error_private_init/copy/clear functions, plus G_DEFINE_POINTER_TYPE and G_DEFINE_POINTER_TYPE_WITH_CODE. It parses with no syntax or unknownMacro errors. With --enable=all, the three private functions get unusedFunction. A G_DEFINE_TYPE file with w_class_init/w_init gives the same warning for those two functions, so this behaviour was already there before the PR.

Automated review of 977dcde by Claude. The pull request was built and tested locally.

Comment thread cfg/gtk.cfg
<define name="G_DEFINE_DYNAMIC_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)" value=""/>
<define name="G_DEFINE_ENUM_TYPE(TypeName, type_name, ...)" value=""/>
<define name="G_DEFINE_ENUM_VALUE(EnumValue, EnumNick)" value=""/>
<define name="G_DEFINE_EXTENDED_ERROR(ErrorType, error_type)" value=""/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

Minor: the real G_DEFINE_EXTENDED_ERROR calls the user-written <error_type>_private_init, _private_copy and _private_clear functions. Because this define expands to nothing, --enable=unusedFunction reports all three as never used. G_DEFINE_TYPE already has the same problem with *_class_init/*_init, so this is consistent and not a blocker. It might still be worth a line in gtk.c, together with the G_DEFINE_POINTER_TYPE* defines, which also have no test yet.

@dmcppcheck

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved.

Added:
G_DEFINE_ENUM_TYPE
G_DEFINE_ENUM_VALUE
G_DEFINE_EXTENDED_ERROR
G_DEFINE_FLAGS_TYPE
G_DEFINE_POINTER_TYPE
G_DEFINE_POINTER_TYPE_WITH_CODE

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no new problems. The earlier AI review already raised the only gaps I saw: G_DEFINE_EXTENDED_ERROR, G_DEFINE_POINTER_TYPE and G_DEFINE_POINTER_TYPE_WITH_CODE have no test code, and the empty expansion leads to unusedFunction reports.

The new gtk.c code passes the cfg check, and every inline suppression in it is used. The G_DEFINE_ENUM_TYPE/G_DEFINE_ENUM_VALUE block runs under --force even though GLIB_CHECK_VERSION is not defined in gtk.cfg, so the new test does cover those defines. The reordered define list has no duplicate names and loses no define. All defines pass the gcc -Werror syntax check that runtests.sh does.

The PR currently has merge conflicts, which was reported earlier.

Testing

  • Built cppcheck in pr/; the build succeeded.
  • Ran the cfg test with the options from test/cfg/runtests.sh:
    ./cppcheck --check-library --platform=unix64 --enable=style,information --inconclusive --force --check-level=exhaustive --inline-suppr --debug-warnings --suppress=checkersReport --library=gtk -q test/cfg/gtk.c
    It printed nothing and exited with 0, so there were no unmatched suppressions.
  • Ran it again without --force and with -DGLIB_CHECK_VERSION(a,b,c)=1: no output.
  • Ran the PR's gtk.c against the base gtk.cfg. It gives gtk.c:716:1: error: ... G_DEFINE_ENUM_TYPE ... [unknownMacro], which shows the new test covers the change.
  • Took every <define> from gtk.cfg with a Python XML parser, wrote them out as #define lines and ran gcc -fsyntax-only -xc -Werror on them. This copies check_defines_syntax; I used Python because xmlstarlet and xmllint are not installed. The check passed, and there are no duplicate define names.
  • Not tested:
    • The compiler syntax check of gtk.c, because GTK and pkg-config are not available in the container.
    • The RelaxNG validation of gtk.cfg, because xmllint is not installed.

Automated review of 59cabea by Claude. The pull request was built and tested locally.

@danmar danmar changed the title gtk.cfg: Complete and sort G_DEFINE_* list Fix #15179 (gtk.cfg: Complete and sort G_DEFINE_* list) Nov 6, 2026
@danmar
danmar merged commit 8df3087 into cppcheck-opensource:main Nov 6, 2026
71 checks passed
@Tamaranch
Tamaranch deleted the add-defines branch November 6, 2026 10:23
xfce-gitbot pushed a commit to xfce-mirror/xfce4-dev-tools that referenced this pull request Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants