llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] `E[...]`/`E(...)` does not evaluate `E` if it calls a `static` overload

Open MitalAshok opened this issue 2 years ago • 3 comments

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

MitalAshok avatar Jan 16 '24 21:01 MitalAshok

@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

llvmbot avatar Jan 16 '24 22:01 llvmbot

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.

shafik avatar Jan 17 '24 02:01 shafik

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

MitalAshok avatar Jan 19 '24 11:01 MitalAshok