ITADN

struct dns_server has a union member also named dns_server — illegal in C++ (include/zephyr/net/dns_resolve.h)

#115947Closedrwrozelle 创建于 9 天前
priority: lowarea: Networkingarea: C++
R
rwrozellecommented
## Title `struct dns_server` has a union member also named `dns_server` — illegal in C++ (`include/zephyr/net/dns_resolve.h`) ## Body ### Describe the bug `struct dns_resolve_context::dns_server` (added/changed in #115432, commit `a33f4fbcd9b5` "net: dns: Use net_sockaddr_storage for address storage") defines an anonymous union member with the same name as its enclosing struct: ```c struct dns_resolve_context { struct dns_server { union { struct net_sockaddr_storage dns_server_addr; /** @cond INTERNAL_HIDDEN */ struct net_sockaddr dns_server; /** @endcond */ }; ... ``` This compiles fine under C, but is ill-formed in C++: a class/struct member may not share the name of its immediately enclosing class ([class.mem] — it collides with the injected-class-name). Any C++ translation unit that includes this header fails to compile. ### To Reproduce Include `zephyr/net/dns_resolve.h` (directly or transitively) from a `.cpp` file and compile. Example error: ``` zephyr/include/zephyr/net/dns_resolve.h:513:45: error: 'dns_resolve_context::dns_server::<unnamed union>::dns_server' has the same name as the class in which it is declared 513 | struct net_sockaddr dns_server; | ^~~~~~~~~~ ``` Hit this building an out-of-tree C++ application (ESPHome's Zephyr platform) against `main` shortly after #115432 merged. ### Expected behavior Header should be valid under both C and C++, per Zephyr's usual policy of keeping public headers C++-safe. Renaming the union member (e.g. to `dns_server_sockaddr` or similar) would resolve it without any other API/ABI impact, since it's inside an anonymous union and gated `INTERNAL_HIDDEN`. ### Impact Twister/CI builds C, not C++, so this wasn't caught pre-merge. Any downstream C++ application including this header (directly or via `net_mgmt`/DNS-adjacent includes) will fail to build starting from this commit. ### Environment - Zephyr main, commit `a33f4fbcd9b5` / PR #115432 (merged 2026-08-11)
关闭于 4 天前 5 条评论