<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 - Modifying data member when passing temporary to function accepting T const & not considered constexpr"
   href="https://bugs.llvm.org/show_bug.cgi?id=32860">32860</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Modifying data member when passing temporary to function accepting T const & not considered constexpr
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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++14
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david@doublewise.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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{});
}




<span class="quote">> clang++ source/main.cpp -std=c++14</span >
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</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>