Skip to content

Commit

Permalink
Fix incorrect handling of private ctors
Browse files Browse the repository at this point in the history
In cases where a factory new method is available on a type, we should not even be attempting to invoke that type's constructor, because the constructor may be private or might not even exist.

Eliminate any instantiations of templates that attempt such invocation.
  • Loading branch information
codemercenary committed Nov 19, 2015
1 parent 38e401d commit c4a9ae4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/autowiring/test/AutoConstructTest.cpp
Expand Up @@ -58,4 +58,28 @@ TEST_F(AutoConstructTest, CanConstructRvalueCtor) {

TEST_F(AutoConstructTest, CanCopyAutoConstruct) {
AutoConstruct<HasDefaultCtorAndOthers> v(100);
}
}

namespace {
class MyPrivateCtorClass {
MyPrivateCtorClass(void):
ival(-10)
{}
MyPrivateCtorClass(int ival) :
ival(ival)
{}

public:
const int ival;

static MyPrivateCtorClass* New(int ival) {
return new MyPrivateCtorClass{ ival };
}
};
}

TEST_F(AutoConstructTest, FactoryNewPrivateCtor) {
AutoConstruct<MyPrivateCtorClass> mpcc{ 1002 };
ASSERT_NE(nullptr, mpcc.get()) << "Null not expected as a return type from a factory new construction";
ASSERT_EQ(1002, mpcc->ival) << "Correct ctor was not invoked on a type with a private ctor";
}

0 comments on commit c4a9ae4

Please sign in to comment.