[llvm-bugs] [Bug 36769] New: clang doesn't to warn about return of reference to temporary when pointers to members are used
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Fri Mar 16 11:02:31 PDT 2018
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=36769
            Bug ID: 36769
           Summary: clang doesn't to warn about return of reference to
                    temporary when pointers to members are used
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andy.somerville at gmail.com
                CC: llvm-bugs at lists.llvm.org
Created attachment 20079
  --> https://bugs.llvm.org/attachment.cgi?id=20079&action=edit
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
-- 
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/20180316/fb195448/attachment.html>
    
    
More information about the llvm-bugs
mailing list