Skip to content

Instantly share code, notes, and snippets.

@EricWF
Created January 4, 2017 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricWF/e328af953a34df6af5070788f600e8bb to your computer and use it in GitHub Desktop.
Save EricWF/e328af953a34df6af5070788f600e8bb to your computer and use it in GitHub Desktop.
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <type_traits>
#include <cassert>
#include "test_macros.h"
struct S {
protected:
S () {}; // ctor is protected
private:
S(int) {}
};
static_assert(std::is_empty<S>::value, "S needs to be empty for these test cases");
int main()
{
std::shared_ptr<S> p;
// expected-error@memory:* 2 {{static_assert failed "Can't construct object in make_shared}}
{
// test that construction via a protected constructor is not accepted.
// NOTE: We may accidentally use a protected constructor while performing the EBO.
p = std::make_shared<S>(); // expected-note {{here}}
}
{
// test that construction via a private constructor is not accepted.
// expected-error@memory:* 1 {{base class 'S' has private constructor}}
p = std::make_shared<S>(42); // expected-note {{here}}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment