Skip to content

Instantly share code, notes, and snippets.

@EricWF EricWF/make_shared.fail.cpp Secret
Created Jan 4, 2017

Embed
What would you like to do?
//===----------------------------------------------------------------------===//
//
// 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
You can’t perform that action at this time.