<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63009>63009</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[[noreturn]] attribute has no effect on constructors
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
9291Sam
</td>
</tr>
</table>
<pre>
```cpp
struct NoReturnConstructor
{
[[noreturn]] NoReturnConstructor()
{
throw int {};
}
};
[[noreturn]] void noReturnFunction()
{
throw int {};
}
int function()
{
NoReturnConstructor();
}
int function2()
{
noReturnFunction();
}
int function3()
{}
int main()
{
function();
function2();
function3();
}
```
Clang 16.0.0 output:
```
<source>:17:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
<source>:25:2: warning: non-void function does not return a value [-Wreturn-type]
{}
^
2 warnings generated.
```
The first warning on like 17 is unexpected as the constructor has a noreturn attribute, and never reaches the end of the function.
GCC 13.1 correctly compiles this snippet of code and returns the following output:
```
<source>: In function 'int function3()':
<source>:25:2: warning: no return statement in function returning non-void [-Wreturn-type]
25 | {}
| ^
```
Clang example: [https://godbolt.org/z/fMMobzT7K]
GCC example [https://godbolt.org/z/eoxqK4zGj]
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU2PozgQ_TXmUgoyJgQ4cOhOJqPVaPawO9KejSmCZx2btU1__fqVITRZOt3qPUwUGcvleu-Vq8rmzsmTRqxIdk-yQ8QH3xlblaxM_uTnqDbNc0V2dPqLvif0QOid83YQHn43f6AfrN4bPa0YO9lJfj9NYIS918aOG0l2INnhph8rCCvh4gUAC8Tl5ztrHkFqP5ryA0lfOfLDTLusXsZb9A9GNqAvGo6DFl4aPQlYy_-Id6Edx7Cj_RDs3bA_A8luY74TxicA0zXg261nLt8_l_Y247WJrW1r7rcy51K7lrJXXJ8g2cU0pmAG3w-epHe3HdK9M4MVSNIvJL1L8jCQ9A4eudVSn8JUG70ZS2BWA41BB9p4mMoEODxwNWAo3s1f09rGP_cY6melN_tyk5hlYfgVxEue4JWczSwOTqjRco9N_MGB_ugQWmmdn_3AaFDyb4QkB-lg0PjUo_DYAHfgOwSxlCx03AGHuaeAe29lPXgkbA9cN6DxAS1Y5KLDyRt1A6Ydp3Po8bWer_s9JGmcgDDWovDqGYQ591KN_tKB07Lv0QcQYRocaSb6iaA1SpnHMZD_Ux7wm15yQVh-qz1YvoB9KsdzLp3nHs-oPcgrlskYlL5Ww7vJBgCWAcn38J-0w3Q97mEpAIBVoPNFOrUOPvFzrzDoI9l9533vQlDsSNjxZJraKB8beyLs-ELYsf3-3dQvP_Jvi5CQoAvIZxDQPP3zbfvy9edVKPM3aqq0KdOSR1gluyLbbou8TKKuqgtBi7wuUyx5km2LHdYipXRXNAXDrKWRrBhlKc1SmrAkpWXMdqzZ1kXR8FrQRHCypXjmUsVKPZyDnEg6N2C1SyktI8VrVG585xjT-AijkTAWnj1bBZ9NPZwc2VIlnXcLipdeXR7I9VPyWvxjV2gD2LYofOinq5Zx0WBVtTo16buhjoU5E3YMVJfPprfmJwpP2HEU6Ag7jgH8GwAA__8Mvj7y">