<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76884>76884</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang assert when capturing constant block in own initializer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ellishg
</td>
</tr>
</table>
<pre>
Clang crashes when trying to capture a constant block in its own initializer. If clang can't handle this case, it should fail with a diagnostic instead of crashing only in assert builds. The crash goes away if `const` is removed.
```objc
#import <Foundation/Foundation.h>
NSUInteger bar(void (^captured)(void));
void foo()
{
// Remove "const" to fix the crash
__block const NSUInteger crashing_block = bar(^{
(void)crashing_block;
});
}
```
```
clang main.mm -c -fblocks -target arm64-apple-macosx -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU02PpDYQ_TXmUmoENt00Bw6704O0yiaRMhspt1WBC6hdY7dsM7OdXx_xMenZSSSEMa569eq5HobAgyWqxfGjOF4SnOPofE3GcBiHpHX6Vj8YtAN0HsNIAV5GshD9je0A0UGH1zh7AoTO2RDRRmiN674DW-AYwL1YYMuR0fDf5FP41EO3AaIVsowwotWGII4coMNAQj4ARwijm42GHtnAC8cREDTjYF2I3AHbEAk1uH4jtrBx1tyWshgC-QjtzEaHFL6MtMXA4CgAvuANuAdxylbG4pQBB_A0uWfSqcguIvuwv0_Z9rj2W7f_koqnq_MRhHpo3Gw1RnZWyOa-SUehHt_i_Pb05ycbaSAPLXohz8-ONQh5FsfHXT8tZLUfrF-VUB_fQqwZvXNLkqz2k3IPARCyEbKBP9YmQEi5tSblckU9_4D4KsJrxtev2zWtgfCG4auc-7lQl520OD7eK965_hz_L20AUV5-6qO8vFP1f6XettuETMg2nSY4dHDoV_gAh4h-oAjop1NxwOvV0GHCzoUfcOBwC965uMjxmVuP_iZkc6FnMu5KXsjmwU0TWv2ZLX1xzgQhm6fLL8vyK3a_P_2VBv39HaFE10pXqsKE6rzMCqXyslLJWEupq0qrknp1Vng6nls6922uKtXKLNcy4VpmssjyrMhyWR1V2mdFR6eyKtuiojxHUWQ0IZvUmOcpdX5IOISZ6vJ0PheJwZZMWI0p5SqIkHLxqK-X-EM7D0EUmeEQwx0hcjS0W3Y3wurYbc4Wm_zXp-88msze1GOM1yDUh22yBo7j3Kadm4Rsllr7crh69426KGSzUl-UXNn_EwAA__9h1V34">