https://github.com/mpark created https://github.com/llvm/llvm-project/pull/155948
I'm having a hard time figuring out what the expected behavior is for this case. If I get rid of the anonymous union and just keep `S` like this: ``` template <typename T> struct S { T x; }; ``` There are no issues. However, I see that merging occurs to avoid any issues in this case. With the `union`, merging logic also occurs there but it doesn't seem to work out properly. But, I'm not sure if this should be triggering merging logic at all? If I structure the `main.cpp` like this: ``` import "hu-01.h"; import "hu-02.h"; void g(S<int>) {} void h() { f(); } ``` There are also no issues, and this time there doesn't seem to be any merging either. **Question**: Should this case (1) not be merging at all? or (2) is it correct to be merging, and we need to fix the logic for merging anonymous `union`s? >From 375388fa16e1b6be76eab1cb1f17139ee22ad1fd Mon Sep 17 00:00:00 2001 From: Michael Park <mcyp...@gmail.com> Date: Thu, 28 Aug 2025 14:38:21 -0700 Subject: [PATCH] [C++20][Modules] Add a test for field info assertion failure. --- clang/test/Modules/anon-union-in-template.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 clang/test/Modules/anon-union-in-template.cpp diff --git a/clang/test/Modules/anon-union-in-template.cpp b/clang/test/Modules/anon-union-in-template.cpp new file mode 100644 index 0000000000000..97fcdc7db86be --- /dev/null +++ b/clang/test/Modules/anon-union-in-template.cpp @@ -0,0 +1,47 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-01 -emit-header-unit -xc++-user-header %t/hu-01.h \ +// RUN: -o %t/hu-01.pcm + +// RUN: %clang_cc1 -std=c++20 -fmodule-name=hu-02 -emit-header-unit -xc++-user-header %t/hu-02.h \ +// RUN: -Wno-experimental-header-units \ +// RUN: -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \ +// RUN: -o %t/hu-02.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \ +// RUN: -Wno-experimental-header-units \ +// RUN: -fmodule-map-file=%t/hu-01.map -fmodule-file=hu-01=%t/hu-01.pcm \ +// RUN: -fmodule-map-file=%t/hu-02.map -fmodule-file=hu-02=%t/hu-02.pcm + +//--- hu-01.map +module "hu-01" { + header "hu-01.h" + export * +} + +//--- hu-02.map +module "hu-02" { + header "hu-02.h" + export * +} + +//--- hu-01.h +#pragma once + +template <typename T> +struct S { union { T x; }; }; + +using SI = S<int>; + +//--- hu-02.h +import "hu-01.h"; +inline void f(S<int> s = {}) { s.x; } + +//--- main.cpp +import "hu-01.h"; +void g(S<int>) {} + +import "hu-02.h"; +void h() { f(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits