Given the example here below, I was surprised to find that despite the default constructor explicitly being deleted (or made default for that matter), aggregate initialization remained possible.
#include <iostream>
struct DefaultPrivate
{
const int n_;
static const DefaultPrivate& create();
private:
DefaultPrivate() = delete;
};
const DefaultPrivate& DefaultPrivate::create()
{
static DefaultPrivate result{10};
return result;
}
int main() {
DefaultPrivate x; //Fails
DefaultPrivate y{10};//Works
return 0;
}
Is the relation between private default (or deleted) construction and aggregate initialization unspecified in the standard?
This was the case on both GCC 6.3 and VCC 2017
The reason I'm asking the question, was that I hoped that changing access to the default constructor would prevent public aggregate initialization