llvm-project
llvm-project copied to clipboard
[Clang] `E[...]`/`E(...)` does not evaluate `E` if it calls a `static` overload
Example:
struct X {
X(int x) {
__builtin_printf("X(%d)\n", x);
}
static void operator()() {
__builtin_printf("operator()\n");
}
static void operator[]() {
__builtin_printf("operator[]\n");
}
static void f(int) {
__builtin_printf("f\n");
}
};
int main() {
X(__builtin_printf("main()1\n"))();
X(__builtin_printf("main() 2\n"))[];
X(__builtin_printf("main() 3\n")).f(0);
}
Prints:
operator()
operator[]
main() 3
X(10)
f
Instead of the expected:
main()1
X(8)
operator()
main() 2
X(9)
operator[]
main() 3
X(10)
f
https://godbolt.org/z/sv14fjMYK
@llvm/issue-subscribers-clang-frontend
Author: Mital Ashok (MitalAshok)
Example:
struct X {
X(int x) {
__builtin_printf("X(%d)\n", x);
}
static void operator()() {
__builtin_printf("operator()\n");
}
static void operator[]() {
__builtin_printf("operator[]\n");
}
static void f(int) {
__builtin_printf("f\n");
}
};
int main() {
X(__builtin_printf("main()1\n"))();
X(__builtin_printf("main() 2\n"))[];
X(__builtin_printf("main() 3\n")).f(0);
}
Prints:
operator()
operator[]
main() 3
X(10)
f
Instead of the expected:
main()1
X(8)
operator()
main() 2
X(9)
operator[]
main() 3
X(10)
f
https://godbolt.org/z/sv14fjMYK
This may be a duplicate of: https://github.com/llvm/llvm-project/issues/67976
Can you try and see if the fix there also fixes your issue.
Yes, I could not find it with a search for the life of me. Hopefully future searchers can find this or the other issue.
Duplicate of #67976