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

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



    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.2
    • Build tools: moc
    • None
    • Linux/X11
    • 5a523981f (dev)


      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.


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



            fabiankosmale Fabian Kosmale
            sjoubert Sylvain Joubert
            0 Vote for this issue
            4 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes