Commit 030047c
authored
[Clang] Eagerly instantiate used constexpr function upon definition. (llvm#73463)
Despite CWG2497 not being resolved, it is reasonable to expect the
following code to compile (and which is supported by other compilers)
```cpp
template<typename T> constexpr T f();
constexpr int g() { return f<int>(); } // #1
template<typename T> constexpr T f() { return 123; }
int k[g()];
// llvm#2
```
To that end, we eagerly instantiate all referenced specializations of
constexpr functions when they are defined.
We maintain a map of (pattern, [instantiations]) independent of
`PendingInstantiations` to avoid having to iterate that list after each
function definition.
We should apply the same logic to constexpr variables, but I wanted to
keep the PR small.
Fixes llvm#732321 parent 8a66510 commit 030047c
File tree
14 files changed
+165
-2
lines changed- clang
- docs
- include/clang
- Sema
- Serialization
- lib
- Sema
- Serialization
- test
- PCH
- SemaTemplate
14 files changed
+165
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
796 | 801 | | |
797 | 802 | | |
798 | 803 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
322 | 325 | | |
323 | 326 | | |
324 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
10087 | 10088 | | |
10088 | 10089 | | |
10089 | 10090 | | |
| 10091 | + | |
| 10092 | + | |
| 10093 | + | |
| 10094 | + | |
| 10095 | + | |
| 10096 | + | |
10090 | 10097 | | |
10091 | 10098 | | |
10092 | 10099 | | |
| |||
10405 | 10412 | | |
10406 | 10413 | | |
10407 | 10414 | | |
| 10415 | + | |
| 10416 | + | |
| 10417 | + | |
10408 | 10418 | | |
10409 | 10419 | | |
10410 | 10420 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
698 | 702 | | |
699 | 703 | | |
700 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
814 | 814 | | |
815 | 815 | | |
816 | 816 | | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
817 | 820 | | |
818 | 821 | | |
819 | 822 | | |
| |||
2101 | 2104 | | |
2102 | 2105 | | |
2103 | 2106 | | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
2104 | 2110 | | |
2105 | 2111 | | |
2106 | 2112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
313 | 319 | | |
314 | 320 | | |
315 | 321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16275 | 16275 | | |
16276 | 16276 | | |
16277 | 16277 | | |
| 16278 | + | |
| 16279 | + | |
| 16280 | + | |
16278 | 16281 | | |
16279 | 16282 | | |
16280 | 16283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19053 | 19053 | | |
19054 | 19054 | | |
19055 | 19055 | | |
19056 | | - | |
| 19056 | + | |
19057 | 19057 | | |
19058 | 19058 | | |
19059 | 19059 | | |
19060 | 19060 | | |
19061 | | - | |
| 19061 | + | |
| 19062 | + | |
| 19063 | + | |
| 19064 | + | |
| 19065 | + | |
| 19066 | + | |
19062 | 19067 | | |
19063 | 19068 | | |
19064 | 19069 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6495 | 6495 | | |
6496 | 6496 | | |
6497 | 6497 | | |
| 6498 | + | |
| 6499 | + | |
| 6500 | + | |
| 6501 | + | |
| 6502 | + | |
| 6503 | + | |
| 6504 | + | |
| 6505 | + | |
| 6506 | + | |
| 6507 | + | |
| 6508 | + | |
| 6509 | + | |
| 6510 | + | |
| 6511 | + | |
| 6512 | + | |
| 6513 | + | |
| 6514 | + | |
| 6515 | + | |
| 6516 | + | |
| 6517 | + | |
| 6518 | + | |
| 6519 | + | |
| 6520 | + | |
| 6521 | + | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
| 6525 | + | |
6498 | 6526 | | |
6499 | 6527 | | |
6500 | 6528 | | |
| |||
0 commit comments