Issue 130652
Summary clang: "function definition is not allowed here" when compiling GNU C with nested functions
Labels clang
Assignees
Reporter carnivorecookies
    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)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to