Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-112870

clang-tidy warnings on static global variables in moc generated code

    XMLWordPrintable

Details

    • Linux/X11
    • 5a523981f (dev), 8cde7151a (6.6), 1f60190fe (tqtc/lts-6.5)

    Description

      Currently upgrading my analysis tools to clang-tidy 16, I now hit readability-static-definition-in-anonymous-namespace warnings (interestingly this check does not seem new to this clang-tidy version, but maybe its implementation has been improved/modified).

      Here is an example of the warning I get:

      <source>/moc_MyWidget.cpp:230:68: warning: 'qt_meta_stringdata_MyWidget' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]
      

      I've quickly looked at the moc code generation and it indeed in an anonymous namespace (both potential implementations in the #if #else blocks).

      In the same idea, there also seems to be additional statics (variables like qt_meta_data_... and qt_meta_extradata_... or the checkNotifySignalValidity_... function) that are not in the anonymous namespace. Maybe that could be made consistent with all these in the anonymous namespace without the static keyword.

      Note: as is the checkNotifySignalValidity_... function may also trigger the new misc-use-anonymous-namespace check (but I don't have examples that trigger this code generation on my code base so did not confirm it). Moving the function in the anonymous namespace without the static keyword as suggested above should take care of that one too.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            fabiankosmale Fabian Kosmale
            sjoubert Sylvain Joubert
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes