Issue 92690
Summary [clang] `static constexpr` variable initialized inside `consteval` function is loosing its value
Labels
Assignees
Reporter hanickadot
    Any variable initialized as `static constexpr` variable inside `consteval` is not keeping its value in runtime:

```c++
consteval const int & get_value() {
    constexpr static int value = 42;
    return value;
}

int foo() {
  return get_value();
}
```

generates assembly (with clang 18.1):
```asm
foo():                                # @foo()
 push    rbp
        mov     rbp, rsp
        mov     eax, dword ptr [rip + get_value()::value]
        pop     rbp
 ret
get_value()::value:
        .long   0    
```

confirmed with clang 16+ to current `main` branch (`597ac471cc7da97ccf957362a7e9f7a52d6910ee` at compiler explorer)

link to example: https://compiler-explorer.com/z/fj6zco3d5

same thing happens to strings and arrays ... their storage is all zeros
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to