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), 681a8fd95 (dev), 380a327e4 (6.8), b558c3b80 (6.7), c78a22b19 (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

        For Gerrit Dashboard: QTBUG-112870
        # Subject Branch Project Status CR V

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: