<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/130652>130652</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang: "function definition is not allowed here" when compiling GNU C with nested functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carnivorecookies
</td>
</tr>
</table>
<pre>
The following code fails to compile on clang 20.1.0 (and earlier versions), but successfully compiles on GCC:
```c
#include <stdio.h>
int main() {
int foo() {
return 1;
}
printf("%d\n", foo());
}
```
with the following error:
```
<source>:4:12: error: function definition is not allowed here
4 | int foo() {
| ^
<source>:7:17: error: call to undeclared function 'foo'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
7 | printf("%d\n", foo());
| ^
2 errors generated.
```
even when using any of the GNU C standards (using any of the following compiler flags: `-std=gnu89`, `-std=gnu99`, `-std=gnu11`, `-std=gnu17`, and `-std=gnu23`)
according to the GNU website, nested functions are supported in GNU C:
<https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>
> A nested function is a function defined inside another function. **Nested functions are supported as an extension in GNU C, but are not supported by GNU C++.**
(emphasis added by me)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE9v6zYM_zTMhYghS3EcH3xw3OZhl-6wDTsrEh1rU6RAktv12w-yk9cmrxs2Q0AUkiJ_P_6TMZqTI2qh2kP1tJJTGn1olQzOvPpAyvs_DcXV0ev39teRcPDW-jfjTqi8JhyksRGTR-XPF2MJvUNlpTshZ0VZMAS-k04jyWANBXylEI13EXgDvMfjlDBOSlGMw2Tt-81NzH6-9T2IDlgHW7Yclf9wYZyykyYE0cekjS9GEM9ZxTrjEp6lccB3wBuEej_LmywfvH8UA2sCpSk4LEHcZPXTcrkE49IwP-HAKw1V7-Zr_-Eqn-Xh8uqGFFj3ZtKI6S5lFIIPD5zyXfTRT0FRpi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