<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 - constexpr variable initialisation error after forwarding reference"
   href="https://bugs.llvm.org/show_bug.cgi?id=43086">43086</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>constexpr variable initialisation error after forwarding reference
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>pkeir@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22413" name="attach_22413" title="Code as described.">attachment 22413</a> <a href="attachment.cgi?id=22413&action=edit" title="Code as described.">[details]</a></span>
Code as described.

The C++11 code below (also attached) will fail to compile:

struct Bar {};
struct Foo { Bar t; };

template <typename T>
constexpr T jam(T &&a) { return a; }

void test()
{
  Foo y;
  constexpr Foo x = jam(y);
}

Changing the types of x and y from Foo to Bar will remove the error. GCC
snapshot 17th August 2019 produces no error. The error message follows:

constexpr_rvalue.cpp:10:17: error: constexpr variable 'x' must be initialized
by a constant expression
  constexpr Foo x = jam(y);
                ^   ~~~~~~
constexpr_rvalue.cpp:10:21: note: read of non-constexpr variable 'y' is not
allowed in a constant expression
  constexpr Foo x = jam(y);
                    ^
constexpr_rvalue.cpp:10:21: note: in call to 'Foo(y)'
constexpr_rvalue.cpp:9:7: note: declared here
  Foo y;
      ^
1 error generated.</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>