Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15
-
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.