In the following code, template structures BB and CC are almost identical except for the constructors. Template BB uses a constructor that does nothing whereas template CC uses the default constructor. When I compile it using Visual Studio 2013 update 4, an error is thrown in the line that declares constInst2 but not on the line that declares constInst:
error C4700: uninitialized local variable 'instance2' used"
I expected the same error when initializing 'instance' as well. Am I misinterpreting this sentence?
"If the implicitly-declared default constructor is not deleted or trivial, it is defined (that is, a function body is generated and compiled) by the compiler, and it has exactly the same effect as a user-defined constructor with empty body and empty initializer list."
struct AA
{
typedef int a;
typedef const int b;
};
template< typename A >
struct BB
{
typename A::a a_A;
typedef typename A::b a_B;
BB()
{};
};
template< typename A >
struct CC
{
typename A::a a_A;
typedef typename A::b a_B;
CC() = default;
};
int main()
{
BB< AA > instance;
BB< AA >::a_B constInst( instance.a_A );
CC< AA > instance2;
CC< AA >::a_B constInst2( instance2.a_A );
return 0;
}
warning C4700: uninitialized local variable 'instance2' usedIt also compiles with no issues here: ideone.com/Hc1jB4 - PaulMcKenzie