<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 - clang doesn't to warn about return of reference to temporary when pointers to members are used"
   href="https://bugs.llvm.org/show_bug.cgi?id=36769">36769</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang doesn't to warn about return of reference to temporary when pointers to members are used
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andy.somerville@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20079" name="attach_20079" title="test case: no warning on returning reference to temp via pointer-to-member">attachment 20079</a> <a href="attachment.cgi?id=20079&action=edit" title="test case: no warning on returning reference to temp via pointer-to-member">[details]</a></span>
test case: no warning on returning reference to temp via pointer-to-member

Expected: Warning about return of reference to temporary

Observed: No warning

Test case (also attached):

////////////////////////////////////////
struct Derp { int b = 66; };

int & memba(Derp obj,int Derp::*mem) {
    return obj.*mem; // <-- would normally warn here if we weren't using
reference to member
}

int main() {
    Derp d;
    return memba(d, &Derp::b);
}
///////////////////////////////////////


There might be a technical reason this cannot be detected, but using pointers
to data member seem to prevent clang from warning about returning a reference
to a temporary.

On the face of it since the value of a pointer to member is not known until
runtime it would seem impossible to warn about what it refers to, but AFAIK,
since pointers to members cannot refer to references, we can deduce that
returning a reference to *any* member of temporary would in turn be returning a
reference to a temporary.


Tested in:

3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7.x (trunk 2018-03-15)

    clang++ -Wall -Wpedantic --std=c++11 warningtestcase.cpp</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>