[LLVMbugs] [Bug 17860] New: wrong lifetime for function parameters

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 8 16:49:26 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=17860

            Bug ID: 17860
           Summary: wrong lifetime for function parameters
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The destructor for a function parameter is called at the wrong time. We delay
until the end of the full-expression containing the call, but the parameter's
lifetime is supposed to end when the function returns. For instance:

  #include <stdio.h>
  struct X {
    const char *p;
    ~X() { puts(p); }
  };
  void f(X, X) {}
  int main() {
    f({"1"}, X{"3"}), X{"2"};
  }

is required to print:

  1
  2
  3

but clang (and edg and g++) print:

  2
  3
  1

and MSVC will presumably print:

  1
  3
  2

(Note that braced initialization of the parameter does not create a temporary.
The same effect can be seen by passing a local variable of type X to the
function.)

If we get this right, we can reduce stack usage in some cases, so it's worth
investigating whether real code will be broken by this.

-- 
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/20131109/808dd31a/attachment.html>


More information about the llvm-bugs mailing list