llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Michael Park (mpark)
<details>
<summary>Changes</summary>
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?
---
Full diff: https://github.com/llvm/llvm-project/pull/155948.diff
1 Files Affected:
- (added) clang/test/Modules/anon-union-in-template.cpp (+47)
``````````diff
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(); }
``````````
</details>
https://github.com/llvm/llvm-project/pull/155948
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits