ui/kbd-state.h: Make the header C++ compatible
PATCH 1/1 ui/kbd-state.h: Make the header C++ compatible
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
--- include/ui/kbd-state.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
include/ui/kbd-state.h +2 -4
@@ -9,9 +9,7 @@#include "qapi/qapi-types-ui.h" -typedef enum QKbdModifier QKbdModifier ; - -enum QKbdModifier { +typedef enum QKbdModifier { QKBD_MOD_NONE = 0, QKBD_MOD_SHIFT,
@@ -23,7 +21,7 @@ enum QKbdModifier {QKBD_MOD_CAPSLOCK , QKBD_MOD__MAX -}; +} QKbdModifier;typedef struct QKbdState QKbdState ;
Signature · 1 line
2.53.0.rc1.225.gd81095ad13-goog
Quoted 7 lines · Roman Kiryanov
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
Signed-off-by Will Hollins <[email protected]>Signed-off-by Roman Kiryanov <[email protected]>
Quoted 32 lines
--- include/ui/kbd-state.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)include/ui/kbd-state.h +2
-5@@ -9,9 +9,7 @@#include "qapi/qapi-types-ui.h" -typedef enum QKbdModifier QKbdModifier ; - -enum QKbdModifier { +typedef enum QKbdModifier { QKBD_MOD_NONE = 0, QKBD_MOD_SHIFT,@@ -23,7 +21,7 @@ enum QKbdModifier {QKBD_MOD_CAPSLOCK , QKBD_MOD__MAX -}; +} QKbdModifier;typedef struct QKbdState QKbdState ; --2.53.0.rc1.225.gd81095ad13-goog
Signature · 1 line
Marc-André Lureau
Hi,
Quoted 26 lines · Roman Kiryanov
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
Signed-off-by Will Hollins <[email protected]>Signed-off-by Roman Kiryanov <[email protected]>--- include/ui/kbd-state.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)include/ui/kbd-state.h +1
-3@@ -9,9 +9,7 @@#include "qapi/qapi-types-ui.h" -typedef enum QKbdModifier QKbdModifier ; - -enum QKbdModifier { +typedef enum QKbdModifier { QKBD_MOD_NONE = 0, QKBD_MOD_SHIFT,
include/ui/kbd-state.h enum QKbdModifier { · line 24
Quoted 5 lines
include/ui/kbd-state.h +1
-1@@ -23,7 +21,7 @@ enum QKbdModifier {QKBD_MOD_CAPSLOCK , QKBD_MOD__MAX -}; +} QKbdModifier;
Yes but:
$ git grep -E 'typedef enum.*;'
hw/core/loader.c:1691:typedef enum HexRecord HexRecord;
hw/display/xlnx_dp.c:259:typedef enum DPGraphicFmt DPGraphicFmt;
hw/display/xlnx_dp.c:260:typedef enum DPVideoFmt DPVideoFmt;
hw/dma/xlnx_dpdma.c:156:typedef enum DPDMABurstType DPDMABurstType;
hw/dma/xlnx_dpdma.c:157:typedef enum DPDMAMode DPDMAMode;
hw/riscv/riscv-iommu.h:28:typedef enum riscv_iommu_igs_modes riscv_iommu_igs_mode;
include/hw/misc/auxbus.h:32:typedef enum AUXCommand AUXCommand;
include/hw/misc/auxbus.h:33:typedef enum AUXReply AUXReply;
include/hw/pci/pci_device.h:52:typedef enum PCIReqIDType PCIReqIDType;
include/hw/ssi/ssi.h:19:typedef enum SSICSMode SSICSMode;
include/hw/xen/interface/io/xenbus.h:51:typedef enum xenbus_state XenbusState;
include/io/channel.h:41:typedef enum QIOChannelFeature QIOChannelFeature;
include/io/channel.h:54:typedef enum QIOChannelShutdown QIOChannelShutdown;
include/system/replay.h:29:typedef enum ReplayClockKind ReplayClockKind;
include/system/replay.h:44:typedef enum ReplayCheckpoint ReplayCheckpoint;
include/ui/clipboard.h:23:typedef enum QemuClipboardType QemuClipboardType;
include/ui/clipboard.h:24:typedef enum QemuClipboardNotifyType QemuClipboardNotifyType;
include/ui/clipboard.h:25:typedef enum QemuClipboardSelection QemuClipboardSelection;
include/ui/kbd-state.h:12:typedef enum QKbdModifier QKbdModifier;
pc-bios/s390-ccw/virtio.h:31:typedef enum VirtioDevType VirtioDevType;
pc-bios/s390-ccw/virtio.h:182:typedef enum guessed_disk_nature_type VirtioGDN;
qapi/opts-visitor.c:63:typedef enum ListMode ListMode;
qapi/string-output-visitor.c:53:typedef enum ListMode ListMode;
target/s390x/gen-features.c:1175: "typedef enum {\n");
tests/qtest/libqos/qgraph_internal.h:30:typedef enum QOSEdgeType QOSEdgeType;
tests/qtest/libqos/qgraph_internal.h:31:typedef enum QOSNodeType QOSNodeType;
tests/unit/check-qom-proplist.c:43:typedef enum DummyAnimal DummyAnimal;If we want QEMU headers to be C++ compilable, we should 1/ fix all enum forward declarations and
2/ add a CI job to ensure no more are added
Hi Philippe, thank you for looking into my patch.
Quoted 15 lines · Philippe Mathieu-Daudé
include/ui/kbd-state.h
Quoted 10 lines · Roman Kiryanov
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
include/ui/kbd-state.h +2
-4-typedef enum QKbdModifier QKbdModifier ; - -enum QKbdModifier { +typedef enum QKbdModifier { -}; +}QKbdModifier ;Yes but:
Quoted 2 lines
$ git grep -E 'typedef enum.*;' include/hw/misc/auxbus.h:32:typedef enum AUXCommand AUXCommand;
I also grepped through the QEMU source code and saw other examples. I limited this patch to ui/kbd-state.h because it is the specific header causing C++ compilation errors in our project. I hesitated to touch the others to keep the diff minimal and avoid changes in files we aren't currently using.
Currently, QEMU has a mix of incompatible and compatible (e.g. block/block-common.h, BlockZoneOp) enum definitions. I think, everything outside the include/ directory should be implementation details.
How would you prefer I proceed?
1) Keep this patch focused: Limit the change to kbd-state.h to fix the active build breakage.
2) Fix public headers: I can send a v2 that fixes this pattern for all files in include/.
3) Tree-wide cleanup: I can attempt to fix every instance found by grep, though this touches private headers as well.
Quoted 1 line
2/ add a CI job to ensure no more are added
Regarding CI: Since our project consumes QEMU headers in a C++ environment, we are effectively serving as a test case for this. We are happy to continue submitting patches as we encounter these compatibility issues.
Quoted 34 lines · Roman Kiryanov
Hi Philippe, thank you for looking into my patch.
Quoted 15 lines · Philippe Mathieu-Daudé
include/ui/kbd-state.h
Quoted 10 lines · Roman Kiryanov
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
include/ui/kbd-state.h +2
-4-typedef enum QKbdModifier QKbdModifier ; - -enum QKbdModifier { +typedef enum QKbdModifier { -}; +}QKbdModifier ;Yes but:
Quoted 2 lines
$ git grep -E 'typedef enum.*;' include/hw/misc/auxbus.h:32:typedef enum AUXCommand AUXCommand;I also grepped through the QEMU source code and saw other examples. I limited this patch to
ui/kbd-state.hbecause it is the specific header causing C++ compilation errors in our project. I hesitated to touch the others to keep the diff minimal and avoid changes in files we aren't currently using.Currently, QEMU has a mix of incompatible and compatible (e.g.
block/block-common.h, BlockZoneOp) enum definitions. I think, everything outside theinclude/directory should be implementation details.
Quoted 8 lines
How would you prefer I proceed?
1) Keep this patch focused: Limit the change to
kbd-state.hto fix the active build breakage.
2) Fix public headers: I can send a v2 that fixes this pattern for all files ininclude/.
3) Tree-wide cleanup: I can attempt to fix every instance found by grep, though this touches private headers as well.
There is also option 4:
4) Don't change this, because QEMU is not a C++ project and it's not a goal for our headers to be compilable with C++, with some minor exceptions.
What are we trying to achieve here, and why does it benefit us as an upstream project ?
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.
thanks
-- PMM
Hi Peter,
(+Paolo / Eric)
Quoted 50 lines · Peter Maydell
Quoted 34 lines · Roman Kiryanov
Hi Philippe, thank you for looking into my patch.
Quoted 15 lines · Philippe Mathieu-Daudé
Review
Quoted 10 lines · Roman Kiryanov
This patch fixes the C++ compilation error:
ISO C++ forbids forward references to 'enum' types
(quoted diff) +2
-4-typedef enum QKbdModifier QKbdModifier; - -enum QKbdModifier { +typedef enum QKbdModifier { -}; +} QKbdModifier;Yes but:
Quoted 2 lines
$ git grep -E 'typedef enum.*;' include/hw/misc/auxbus.h:32:typedef enum AUXCommand AUXCommand;I also grepped through the QEMU source code and saw other examples. I limited this patch to
ui/kbd-state.hbecause it is the specific header causing C++ compilation errors in our project. I hesitated to touch the others to keep the diff minimal and avoid changes in files we aren't currently using.Currently, QEMU has a mix of incompatible and compatible (e.g.
block/block-common.h, BlockZoneOp) enum definitions. I think, everything outside theinclude/directory should be implementation details.Quoted 8 lines
How would you prefer I proceed?
1) Keep this patch focused: Limit the change to
kbd-state.hto fix the active build breakage.
2) Fix public headers: I can send a v2 that fixes this pattern for all files ininclude/.
3) Tree-wide cleanup: I can attempt to fix every instance found by grep, though this touches private headers as well.There is also option 4:
4) Don't change this, because QEMU is not a C++ project and it's not a goal for our headers to be compilable with C++, with some minor exceptions.
Quoted 7 lines
What are we trying to achieve here, and why does it benefit us as an upstream project ?
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.
I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
See for example non-invasive commit 7246c4cc470 ("exec: don't use void* in pointer arithmetic in headers"):
-- >8 --
include/exec/memory.h +1 -1
@@ -2767 +2767 @@ struct MemoryRegionCache { -void *ptr; +uint8_t *ptr;
---
or commit 17c7df806b3 ("exec: avoid using C++ keywords in function parameters"):
-- >8 --
include/exec/memory.h +2 -2
@@ -928 +928 @@ struct MemoryListener { - int old, int new); + int old_val, int new_val);
@@ -947 +947 @@ struct MemoryListener { - int old, int new); + int old_val, int new_val);
---
In this particular case, I always have been confused about what would be the size of forward-declared enums. The C99 standard chapter §6.7.2.2 point 4 mentions:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
When compiling this file with -Werror=pedantic we get:
In file included from ../../ui/kbd-state.c:10:include/ui/kbd-state.h:12:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]
12 | typedef enum QKbdModifier QKbdModifier;
| ^
So arguably this could be fixed for C.
On another perspective, having more contributors should keep our project healthy, and would potentially bring us more reviewers (maintainers?).
If we don't object to take such patches, my only request is to have a CI job for non-C++ developers to not breaking the headers over time.
My 2 cents :)
Regards,
Phil.
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Peter,
(+Paolo / Eric)
Quoted 4 lines · Peter Maydell
What are we trying to achieve here, and why does it benefit us as an upstream project ?
Quoted 8 lines
Quoted 4 lines
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
Every bit of code that is written by some downstream in C++ is some thing that will essentially then never be upstreamed without a big rewrite. So making it easier for downstreams to use C++ reduces our chances of seeing them contribute what they do back to us.
It's also extra work for us (for instance in this thread you proposed adding a CI job, which is more CI minutes cost to the project, more work for maintainers when something that builds fine locally falls over in the CI, and so on).
Each individual fix might be trivial, but they add up. So it matters whether this one is "this is the only thing we tripped over since 2024" or "we just rebased to a new QEMU version and are going to be submitting dozens of these over the next few weeks".
Quoted 5 lines
See for example non-invasive commit
7246c4cc470("exec: don't use void* in pointer arithmetic in headers"):or commit
17c7df806b3("exec: avoid using C++ keywords in function parameters"):
For the record, I wasn't really enthusiastic about those changes either, for essentially the same reasons.
Quoted 11 lines
In this particular case, I always have been confused about what would be the size of forward-declared enums. The C99 standard chapter §6.7.2.2 point 4 mentions:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
When compiling this file with -Werror=pedantic we get:
Quoted 7 lines
In file included from
../../ui/kbd-state.c:10:include/ui/kbd-state.h:12:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]12 | typedef enum QKbdModifier QKbdModifier; | ^So arguably this could be fixed for C.
Yes, I actually like the specific change in the patch on style grounds. I'm just not a fan of "we should make our headers compile with some other programming language that we don't use". C++ should have a better foreign function interface for consuming C headers that doesn't mandate changes to the headers it imports :-)
thanks
-- PMM
Quoted 36 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Peter,
(+Paolo / Eric)
Quoted 4 lines · Peter Maydell
What are we trying to achieve here, and why does it benefit us as an upstream project ?
Quoted 8 lines
Quoted 4 lines
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
Every bit of code that is written by some downstream in C++ is some thing that will essentially then never be upstreamed without a big rewrite. So making it easier for downstreams to use C++ reduces our chances of seeing them contribute what they do back to us.
It's also extra work for us (for instance in this thread you proposed adding a CI job, which is more CI minutes cost to the project, more work for maintainers when something that builds fine locally falls over in the CI, and so on).
Each individual fix might be trivial, but they add up. So it matters whether this one is "this is the only thing we tripped over since 2024" or "we just rebased to a new QEMU version and are going to be submitting dozens of these over the next few weeks".
Quoted 8 lines
Quoted 5 lines
See for example non-invasive commit
7246c4cc470("exec: don't use void* in pointer arithmetic in headers"):or commit
17c7df806b3("exec: avoid using C++ keywords in function parameters"):For the record, I wasn't really enthusiastic about those changes either, for essentially the same reasons.
+1
[...]
Quoted 62 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Peter,
(+Paolo / Eric)
Quoted 4 lines · Peter Maydell
What are we trying to achieve here, and why does it benefit us as an upstream project ?
Quoted 8 lines
Quoted 4 lines
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
Every bit of code that is written by some downstream in C++ is some thing that will essentially then never be upstreamed without a big rewrite. So making it easier for downstreams to use C++ reduces our chances of seeing them contribute what they do back to us.
It's also extra work for us (for instance in this thread you proposed adding a CI job, which is more CI minutes cost to the project, more work for maintainers when something that builds fine locally falls over in the CI, and so on).
Each individual fix might be trivial, but they add up. So it matters whether this one is "this is the only thing we tripped over since 2024" or "we just rebased to a new QEMU version and are going to be submitting dozens of these over the next few weeks".
Quoted 5 lines
See for example non-invasive commit
7246c4cc470("exec: don't use void* in pointer arithmetic in headers"):or commit
17c7df806b3("exec: avoid using C++ keywords in function parameters"):For the record, I wasn't really enthusiastic about those changes either, for essentially the same reasons.
Quoted 17 lines
In this particular case, I always have been confused about what would be the size of forward-declared enums. The C99 standard chapter §6.7.2.2 point 4 mentions:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
When compiling this file with -Werror=pedantic we get:
In file included from
../../ui/kbd-state.c:10:include/ui/kbd-state.h:12:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]12 | typedef enum QKbdModifier QKbdModifier; | ^
Quoted 4 lines
Quoted 1 line
So arguably this could be fixed for C.
Yes, I actually like the specific change in the patch on style grounds.
The *current* code style, however, matches the style we use for the struct declaration & typedefs, and it is natural to be consistent in this way.
Even within this one file we have this example:
typedef enum QKbdModifier QKbdModifier;
typedef struct QKbdState QKbdState;
And so personally I think the current code is preferrable to this patch.
IMHO, if downstream users/developers of a fork really strongly don't want to be writing new devices in C, then the focus should be on Rust as the next generation language, not the C++.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 63 lines · Daniel P. Berrangé
Quoted 62 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Peter,
(+Paolo / Eric)
Quoted 4 lines · Peter Maydell
What are we trying to achieve here, and why does it benefit us as an upstream project ?
Quoted 8 lines
Quoted 4 lines
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
Every bit of code that is written by some downstream in C++ is some thing that will essentially then never be upstreamed without a big rewrite. So making it easier for downstreams to use C++ reduces our chances of seeing them contribute what they do back to us.
It's also extra work for us (for instance in this thread you proposed adding a CI job, which is more CI minutes cost to the project, more work for maintainers when something that builds fine locally falls over in the CI, and so on).
Each individual fix might be trivial, but they add up. So it matters whether this one is "this is the only thing we tripped over since 2024" or "we just rebased to a new QEMU version and are going to be submitting dozens of these over the next few weeks".
Quoted 5 lines
See for example non-invasive commit
7246c4cc470("exec: don't use void* in pointer arithmetic in headers"):or commit
17c7df806b3("exec: avoid using C++ keywords in function parameters"):For the record, I wasn't really enthusiastic about those changes either, for essentially the same reasons.
Quoted 17 lines
In this particular case, I always have been confused about what would be the size of forward-declared enums. The C99 standard chapter §6.7.2.2 point 4 mentions:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
When compiling this file with -Werror=pedantic we get:
In file included from
../../ui/kbd-state.c:10:include/ui/kbd-state.h:12:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]12 | typedef enum QKbdModifier QKbdModifier; | ^
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
So arguably this could be fixed for C.
Yes, I actually like the specific change in the patch on style grounds.
The *current* code style, however, matches the style we use for the struct declaration & typedefs, and it is natural to be consistent in this way.
Per the ISO C standard, maybe we should considerate following the same structure style for enum typedefs was a mistake, and update our coding style. This is what I suggested here:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 14 lines
Even within this one file we have this example:
typedef enum QKbdModifier QKbdModifier; typedef struct QKbdState QKbdState;And so personally I think the current code is preferrable to this patch.
IMHO, if downstream users/developers of a fork really strongly don't want to be writing new devices in C, then the focus should be on Rust as the next generation language, not the C++.
With regards,
Daniel
Quoted 73 lines · Philippe Mathieu-Daudé
Quoted 63 lines · Daniel P. Berrangé
Quoted 62 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Peter,
(+Paolo / Eric)
Quoted 4 lines · Peter Maydell
What are we trying to achieve here, and why does it benefit us as an upstream project ?
Quoted 8 lines
Quoted 4 lines
cf previous email thread from 2024
https://lore.kernel.org/qemu-devel/[email protected]/
about "drip-feeding" of this kind of patch with no clear take on what the end state is or how much churn it's going to induce.I clearly know QEMU is not a C++ project. Now I don't see why we should be reluctant to have headers being usable by a C++ compiler, as long as it doesn't make our project worst to maintain.
Every bit of code that is written by some downstream in C++ is some thing that will essentially then never be upstreamed without a big rewrite. So making it easier for downstreams to use C++ reduces our chances of seeing them contribute what they do back to us.
It's also extra work for us (for instance in this thread you proposed adding a CI job, which is more CI minutes cost to the project, more work for maintainers when something that builds fine locally falls over in the CI, and so on).
Each individual fix might be trivial, but they add up. So it matters whether this one is "this is the only thing we tripped over since 2024" or "we just rebased to a new QEMU version and are going to be submitting dozens of these over the next few weeks".
Quoted 5 lines
See for example non-invasive commit
7246c4cc470("exec: don't use void* in pointer arithmetic in headers"):or commit
17c7df806b3("exec: avoid using C++ keywords in function parameters"):For the record, I wasn't really enthusiastic about those changes either, for essentially the same reasons.
Quoted 17 lines
In this particular case, I always have been confused about what would be the size of forward-declared enums. The C99 standard chapter §6.7.2.2 point 4 mentions:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
When compiling this file with -Werror=pedantic we get:
In file included from
../../ui/kbd-state.c:10:include/ui/kbd-state.h:12:14: error: ISO C forbids forward references to 'enum' types [-Werror,-Wpedantic]12 | typedef enum QKbdModifier QKbdModifier; | ^Quoted 8 lines
Quoted 4 lines
Quoted 1 line
So arguably this could be fixed for C.
Yes, I actually like the specific change in the patch on style grounds.
The *current* code style, however, matches the style we use for the struct declaration & typedefs, and it is natural to be consistent in this way.
Quoted 5 lines
Per the ISO C standard, maybe we should considerate following the same structure style for enum typedefs was a mistake, and update our coding style. This is what I suggested here:
Is ISO C conformance really a compelling argument?
We are relying on multiple Gcc / Clang C extensions. Forward-declared enums is just one of them.
Quoted 6 lines
Quoted 6 lines
Even within this one file we have this example:
typedef enum QKbdModifier QKbdModifier; typedef struct QKbdState QKbdState;And so personally I think the current code is preferrable to this patch.
I think the current code is just fine.
Quoted 3 lines
Quoted 3 lines
IMHO, if downstream users/developers of a fork really strongly don't want to be writing new devices in C, then the focus should be on Rust as the next generation language, not the C++.
Their funeral.
Can't see why we'd be interested in enabling it, though.
Hello Peter, thank you for looking.
Quoted 9 lines · Peter Maydell
Quoted 1 line
How would you prefer I proceed?
There is also option 4:
4) Don't change this, because QEMU is not a C++ project and it's not a goal for our headers to be compilable with C++, with some minor exceptions.
What are we trying to achieve here, and why does it benefit us as an upstream project ?
The Goal: to cleanup the specific header include/ui/kbd-state.h by removing a redundant enum declaration. I realize my original patch description focused on C++, so I will update the commit message in v2 to reflect this cleanup as the primary goal.
The Benefit to Upstream: Currently, this file uses a verbose style where a forward declaration immediately precedes the definition.
In this context, the forward declaration is effectively dead code. My patch consolidates this into the cleaner, standard C idiom found elsewhere in the tree (e.g. include/block/block-common.h):
We are proposing this change because kbd-state.h is a public interface header causing friction for downstream C++ consumers. By adopting the cleaner C idiom here (which benefits QEMU by removing redundancy), we also resolve that downstream friction as a side effect.