<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/65892>65892</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Empty fold `and` expression yields a no-op instead of a forever running loop
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kl31tz
      </td>
    </tr>
</table>

<pre>
    Empty fold `and` expression yields a no-op instead of a forever running loop when used as the condition.

The [standard](https://en.cppreference.com/w/cpp/language/fold#Explanation) states:
When a unary fold is used with a pack expansion of length zero, only the following operators are allowed:
1) Logical AND (&&). The value for the empty pack is **true**
...

Yet in the following example, gcc produces the correct while (true) code but clang reduces `foo` to a no-op. Both successfully evaluate `static_assert(((I, false) and ...));` to true, suprisingly.
``` C++
#include <tuple>
#include <utility>

template <auto... I>
void bar(std::index_sequence<I...>) {
    static_assert(((I, false) and ...));
    while (((I, false) and ...));
}

void foo() {
 bar(std::make_index_sequence<0>{});
}
```

[https://godbolt.org/z/off37csva](https://godbolt.org/z/off37csva)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslF1r8zgThn-NcjLUOFLsxAc-yEcNhZf3aGHZozKRxra2iuTVR9L01y9y0j59umVZloXBCZZn7vuakYQh6MEStazaseqwwBRH59sXI5bxbXF06to-nqZ4hd4ZBawu0SpWl0Cvk6cQtLNw1WRUAATrHtwE2oZIqMD1gNA7T2fy4JO12g5gnJvgMpKFFEgBBogjgXRW6aidLVh5YOX29vxlJGDVLkS0Cr1i1YHxzRjjFJjYMt4x3pEt5DR56smTlVRId2K8uzDeyWlivDNoh4QDMd5l_4yLx9fJoMUsxngDIWKkud4s-Wt2hpAs-juxDjenFx1HQJhQvmR2tDO668GQHeIIb-Qd43tw1lxnpt4Z4y6Z2U3kMTofAD0B5tekPiSX2cb_3KAlGtj-_wCMbxiv52gKyE04o0m5oJ8L0zyO2YgOwPiW8W30iW7_bkWL4qdO_kYRtP1ii17xNBnKpgcpYfJOJUnvA_GeZITLqA1lRzeBBqRTBMcUQebWgqdbDqvL3rm8L6J73wgF7FwcISQpKYQ-GXMFyigYKSfk1mv5jCGQjzN0jqfsp0cTZjm0CjILb3KI3V3h5mYPIU1eB20Hc33nrctbwJ7xXY7bay60lSYpAib2MWVu8fjdWora6Hj9sTo_I50mM_sWe0zRFUUBTx_fnJ1WcETP-CbEebJiq62i1-dAf6S8MZnYP2UO8Zip2PpuCwDgX7XhI_tjQP88ja0Pn9Fm83l4ucBnb1-ATvhCz3-hKjPSepdrfivxPo7Piqza_XyKB6eOzsTC-YHx7o3xzvW9WMtwxu8O_d99zpuFaoVqRIMLapd1sxKrarPaLMZWyKYX9WrD6w0_rpdcrnpe1VWzXK16RMEXuuUlF2WzLJdLseabosKqbo5CVdT3kpdLtirphNoUxpxPWX6hQ0jU1tWm4QuDRzJhvkc5t3SBeZFxnq9V3-ach2MaAluVRocYflSJOhr6z6_ZRfKm_dI5Hcd0vN-SWf7-8zB59zvJyHg3mw6MdzPUnwEAAP__w4jgiA">