[llvm-bugs] [Bug 32860] New: Modifying data member when passing temporary to function accepting T const & not considered constexpr

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 29 15:44:43 PDT 2017


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

            Bug ID: 32860
           Summary: Modifying data member when passing temporary to
                    function accepting T const & not considered constexpr
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: llvm-bugs at lists.llvm.org

struct S {
        constexpr S() {
                x = true;
        }

        bool x = false;
};

constexpr bool f(S const &) {
        return true;
}

// Test passes if you define FIX
#ifdef FIX
constexpr bool f(S &&) {
        return true;
}
#endif

int main() {
        // All of these work    
        constexpr auto lvalue = S{};
        constexpr auto rvalue_member = S{}.x;
        constexpr auto lvalue_member = lvalue.x;
        constexpr auto lvalue_function_call = f(lvalue);

        // This fails
        constexpr auto rvalue_function_call = f(S{});
}




> clang++ source/main.cpp -std=c++14
source/main.cpp:28:17: error: constexpr variable 'rvalue_function_call' must be
initialized by a constant expression
        constexpr auto rvalue_function_call = f(S{});
                       ^                      ~~~~~~
source/main.cpp:3:5: note: modification of object of const-qualified type
'const bool' is not allowed in a constant expression
                x = true;
                  ^
source/main.cpp:28:42: note: in call to 'S()'
        constexpr auto rvalue_function_call = f(S{});
                                                ^
1 error generated.





This same error happens with -std=c++1z. This code was accepted in clang 3.9

-- 
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/20170429/cb73d694/attachment.html>


More information about the llvm-bugs mailing list