Bug 217200 - std::make_shared does not perform zero initialization
Summary: std::make_shared does not perform zero initialization
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 10.3-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL: https://bugs.llvm.org/show_bug.cgi?id...
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-18 13:59 UTC by Dimitry Andric
Modified: 2017-02-18 15:26 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2017-02-18 13:59:33 UTC
From https://bugs.llvm.org/show_bug.cgi?id=32002:

On FreeBSD 10.3, the following program displays "123", but "0" is expected:

#include <memory>
#include <iostream>

int main()
{
    std::make_shared<int>(123);
    std::cout << *std::make_shared<int>();
    return 0;
}

The second std::make_shared reuses the piece of memory of the first one. But it should initialize it to zero, as if "new (ptr) int()" is called, where ptr is the address of allocated memory.
Comment 1 commit-hook freebsd_committer freebsd_triage 2017-02-18 14:44:50 UTC
A commit references this bug:

Author: dim
Date: Sat Feb 18 14:44:14 UTC 2017
New revision: 313916
URL: https://svnweb.freebsd.org/changeset/base/313916

Log:
  Pull in r242377 from upstream libc++ trunk (by Marshall Clow):

    Make sure that __libcpp_compressed_pair_imp default-constructs its'
    members, rather than value-initializing them. Fixes PR#24137

  This ensures std::make_shared<>'s default constructor properly
  initializes to zero.

  Direct commit to stable/9 and stable/10, since stable/11 and head
  already have a newer version of libc++, including this fix.

  Reported by:	martin.beran@kernun.cz
  PR:		217200

Changes:
  stable/10/contrib/libc++/include/memory
  stable/9/contrib/libc++/include/memory