llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

Weird behavior when returning pointer to static local variable from consteval function #116672

Closed Eczbek closed 2 hours ago

Eczbek commented 2 hours ago

https://godbolt.org/z/j58z8175s

#include <print>

consteval const int* foo() {
    static constexpr int x = 5;
    return &x;
}

int main() {
    std::print("{}", *foo());
}

GCC prints 5 as expected, but Clang prints 0.

llvmbot commented 2 hours ago

@llvm/issue-subscribers-clang-frontend

Author: None (Eczbek)

https://godbolt.org/z/j58z8175s ```cpp #include <print> consteval const int* foo() { static constexpr int x = 5; return &x; } int main() { std::print("{}", *foo()); } ``` GCC prints `5` as expected, but Clang prints `0`.
Fznamznon commented 2 hours ago

Perhaps a duplicate of https://github.com/llvm/llvm-project/issues/82994 .

Eczbek commented 2 hours ago

Perhaps a duplicate of #82994 .

Looks like it.