<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Function pointer types defined using std::declval cannot be default initialized in a struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=47377">bug 47377</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Function pointer types defined using std::declval cannot be default initialized in a struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=47377#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Function pointer types defined using std::declval cannot be default initialized in a struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=47377">bug 47377</a>
              from <span class="vcard"><a class="email" href="mailto:richard-llvm@metafoo.co.uk" title="Richard Smith <richard-llvm@metafoo.co.uk>"> <span class="fn">Richard Smith</span></a>
</span></b>
        <pre>Here's the diagnostic:

<source>:5:8: error: reference member 'fptr' binds to a temporary object whose
lifetime would be shorter than the lifetime of the constructed object
struct S {
       ^
<source>:10:7: note: in implicit default constructor for 'S' first required
here
    S thing;
      ^
<source>:6:17: note: initializing field 'fptr' with default member initializer
  function_type fptr = nullptr;
                ^      ~~~~~~~

So, this is telling you:

1) 'fptr' is a reference member.

   That's because declval always returns by reference, and decltype captures
that reference type. function_type is not a pointer-to-function type, it's a
reference-to-pointer-to-function type. In fact, because declval returns an
rvalue reference unless you give it an lvalue reference type, function_type is
an rvalue reference type.

2) When initializing 'fptr' using its default member initializer from the
implicit default constructor for 'S', we would bind that reference member to a
temporary object.

   That's because you provided an initializer of a different type
(std::nullptr_t) that we needed to convert to the referenced type of the
reference (the function pointer type), and that's done by creating a temporary
object of function pointer type, initialized from nullptr, and binding the
reference to the temporary.

3) The lifetime of that temporary object ends too soon to be useful.

   Temporary objects live on the stack, so they never outlive the function in
which they were constructed. In this case, that means the temporary function
pointer object would have gone away before the S default constructor returns,
so the default constructor would result in a broken object containing a
dangling reference.

4) That's an error.

   This changed in a semi-recent C++ language defect report resolution
(effectively, a bug fix for the C++ language). It used to be the case that this
situation just gave you a broken object with a dangling reference, and the
language bug fix says that that situation is simply a programming error. More
recent versions of Clang implement the language bug fix, so they reject your
(incorrect) code.</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>