Commit 705b996
authored
Allow weak/selectany external definitions in header units. (#162713)
weak and selectany are mechanisms for allowing the linker to resolve ODR
violations. [module.import/6] states
> A header unit shall not contain a definition of a non-inline function
or variable whose name has external linkage.
But this prevents compiling any headers with such weak symbols defined.
These occur in eg. some Windows SDK headers like `DirectXMath.h`.
```
#ifndef XMGLOBALCONST
#if defined(__GNUC__) && !defined(__MINGW32__)
#define XMGLOBALCONST extern const __attribute__((weak))
#else
#define XMGLOBALCONST extern const __declspec(selectany)
#endif
#endif
XMGLOBALCONST XMVECTORF32 g_XMSinCoefficients0 = { { { -0.16666667f, +0.0083333310f, -0.00019840874f, +2.7525562e-06f } } };
```
Proposed solution: Do not emit `diag::err_extern_def_in_header_unit` if
the `FD` or `VDecl` have either `SelectAnyAttr` or `WeakAttr`.1 parent f98a256 commit 705b996
File tree
2 files changed
+34
-6
lines changed- clang
- lib/Sema
- test/CXX/module/module.import
2 files changed
+34
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13816 | 13816 | | |
13817 | 13817 | | |
13818 | 13818 | | |
13819 | | - | |
13820 | | - | |
| 13819 | + | |
| 13820 | + | |
| 13821 | + | |
| 13822 | + | |
| 13823 | + | |
| 13824 | + | |
| 13825 | + | |
| 13826 | + | |
13821 | 13827 | | |
13822 | 13828 | | |
13823 | 13829 | | |
13824 | 13830 | | |
13825 | | - | |
| 13831 | + | |
| 13832 | + | |
13826 | 13833 | | |
13827 | 13834 | | |
13828 | 13835 | | |
| |||
16153 | 16160 | | |
16154 | 16161 | | |
16155 | 16162 | | |
16156 | | - | |
16157 | | - | |
| 16163 | + | |
| 16164 | + | |
| 16165 | + | |
| 16166 | + | |
| 16167 | + | |
| 16168 | + | |
16158 | 16169 | | |
| 16170 | + | |
| 16171 | + | |
| 16172 | + | |
16159 | 16173 | | |
16160 | 16174 | | |
16161 | 16175 | | |
16162 | 16176 | | |
16163 | 16177 | | |
16164 | 16178 | | |
16165 | | - | |
| 16179 | + | |
| 16180 | + | |
16166 | 16181 | | |
16167 | 16182 | | |
16168 | 16183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments