Issue |
149749
|
Summary |
__func__ cannot share addresses with string literals in C
|
Labels |
new issue
|
Assignees |
|
Reporter |
Halalaluyafail3
|
The following program demonstrates this issue:
```c
#include<stdio.h>
int main(){
static const char X[]="main";
printf("%i\n",__func__=="main");
printf("%i\n",X=="main");
}
```
Clang prints 1 then 0 with this program, when it should print 0 then 0.
> The identifier \_\_func\_\_ shall be implicitly declared by the translator as if, immediately following
the opening brace of each function definition, the declaration
>
> static const char \_\_func\_\_[] = "function-name";
>
> appeared, where function-name is the name of the lexically-enclosing function.
Section 6.4.2.2 "Predefined identifiers" Paragraph 1 ISO/IEC 9899:2024
Unlike C++, C doesn't say that \_\_func\_\_ can share addresses with string literals so `__func__=="main"` should be zero for the same reason that `X=="main"` is zero.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs