[llvm-bugs] [Bug 27989] New: Subexpression not valid in a constant expression even when it is valid

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 3 04:46:34 PDT 2016


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

            Bug ID: 27989
           Summary: Subexpression not valid in a constant expression even
                    when it is valid
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: michele.caini at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider the following code:

    template<int... V>
    static constexpr int f(int v) {
        int a[] = { (v ^= V, 0)... };       // Line 3
        return v;
    }

    static constexpr int i = f<0x00>(0x11); // Line 7

    int main() { }

It doesn't compile with the following error:

main.cpp:7:22: error: constexpr variable 'i' must be initialized by a constant
expression
[...]
main.cpp:3:23: note: subexpression not valid in a constant expression

Note that it doesn't work as well even if no templates are involved:

    static constexpr int mix(int v, int u) {
        int a[] = { (v ^= u, 0) };
        return v;
    }

    static constexpr int mf = mix(0x11, 0x00);

    int main() { }

For such kind of assignments are allowed in constant expressions, it should
compile.

-- 
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/20160603/6c8b818e/attachment.html>


More information about the llvm-bugs mailing list