[llvm-bugs] [Bug 42518] New: Fold-expression doesn't properly look up operator

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 5 05:49:21 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42518

            Bug ID: 42518
           Summary: Fold-expression doesn't properly look up operator
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: barry.revzin at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

>From StackOverflow (https://stackoverflow.com/q/56898075/2069064):

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));
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190705/bd732142/attachment.html>


More information about the llvm-bugs mailing list