<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Fold-expression doesn't properly look up operator"
   href="https://bugs.llvm.org/show_bug.cgi?id=42518">42518</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Fold-expression doesn't properly look up operator
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>barry.revzin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>From StackOverflow (<a href="https://stackoverflow.com/q/56898075/2069064">https://stackoverflow.com/q/56898075/2069064</a>):

enum Enum {
    A = 3,
    B = 8,
    C = 5
};

namespace EnumMax {
constexpr Enum operator>>=(const Enum left, const Enum right) {
    return left < right ? right : left;
}
}

template<Enum ... enums>
constexpr Enum max() {
    using EnumMax::operator>>=;
    return (enums >>= ...);
}

constexpr Enum max_v = max<A, B, C>();

The fold-expression (enums >>= ...) does not find the operator>>= brought in
with the using-declaration. The error reported is:

<source>:16:23: error: expression is not assignable
    return (enums >>= ...);
            ~~~~~     ^

The same is true if enums is a function parameter pack instead of a template
non-type parameter pack.

Manually expanding the pack (as the OP in the question demonstrates) does
compile:

template<Enum e1, Enum e2, Enum e3>
constexpr Enum max() {
    using EnumMax::operator>>=;
    return (e1 >>= (e2 >>= e3));
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>