Issue 134820
Summary Constexpr allocating temporaries in `if constexpr` are rejected.
Labels new issue
Assignees
Reporter MiroPalmu
    Clang fails to compile following while gcc allows it:

https://godbolt.org/z/KcqTdeodx

```cpp
#include <vector>

// ok
static_assert(!std::vector{1,2,3}.empty());

int main() {
    if constexpr(!std::vector{1,2,3}.empty()) {
        return 1;
 }
    return 0;
}
```

Error message:

```
<source>:7:18: error: constexpr if condition is not a constant _expression_
    7 |     if constexpr(!std::vector{1,2,3}.empty()) {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.1/../../../../include/c++/15.0.1/bits/alloc_traits.h:614:20: note: allocation performed here was not deallocated
  614 |       { return __a.allocate(__n); }
      |      
```

The same conditional is allowed in `static_assert` but not in `if constexpr`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to