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

moc assumes all headers should only be included once

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15
    • Build tools: moc
    • None

    Description

      mocĀ ignores #include if the header file has already been processed, but that is non-conformant. In particular, this leads to parser errors when including certain protobuf-generated code.

      This is a simplified *.pb.h header:

      #include <google/protobuf/port_def.inc>
      #include <google/protobuf/port_undef.inc>
      #include <google/protobuf/port_def.inc>
      
      namespace example {
      enum ExampleEnum : int {
          Add = 0,
          Explode PROTOBUF_DEPRECATED_ENUM = 1,
          Erase = 2
      }
      }

      "port_def.inc" has a set of #define and "port_undef.inc" has corresponding #undef. Because moc ignores the second include of "port_def.inc", macros including PROTOBUF_DEPRECATED_ENUM are never re-defined and moc fails when parsing this enum.

      The attached example reproduces this with moc test.h

      If I understand correctly, traditional #ifdef include guards would already work. I think the restriction on re-including could be removed if moc supported #pragma once, which would solve the protobuf case.

      As a workaround, we are currently patching moc to ignore port_undef.inc specifically.

      Attachments

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

        Activity

          People

            fabiankosmale Fabian Kosmale
            special John Brooks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes