Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A { // no default constructor
- public:
- A(int i) : i_(i) {}
- private:
- int i_ = 0;
- };
- class B { // defines default constructor
- public:
- B() {}
- B(int i) : i_(i) {}
- private:
- int i_ = 0;
- };
- void foo()
- {
- // ** - it is the same before and after patch, but behaviour is questionable.
- // ! - different before and after patch, but still producess error in the same statement.
- // !! - compiler treats statement completely different. E.g. it was compileable before
- // patch and is not compileable after it.
- // after patch -> before patch
- //
- // Sanity check for non-arrays
- //
- new A(1); // ok
- new A(); // error: no matching constructor for initialization of 'A'
- new B(1); // ok
- new B(); // ok
- //
- // Simple cases, no default constructor
- //
- new A[0]; // ** expected ok, not error: no matching constructor for initialization of 'A'
- // A::A() is NOT expected to be constructed
- new A[0] {}; // !! ok -> error: no matching constructor for initialization of 'A'
- // A::A() is NOT expected to be constructed
- new A[0] { {1} }; // ! error: excess elements in array 'new' initializer -> error: no matching constructor for initialization of 'A'
- new A[1]; // error: no matching constructor for initialization of 'A'
- new A[1] {}; // error: no matching constructor for initialization of 'A'
- new A[1] { {1} }; // !! ok -> error: no matching constructor for initialization of 'A'
- new A[2] { {1} }; // error: no matching constructor for initialization of 'A'
- new A[2] { {1}, {2} }; // !! ok -> error: no matching constructor for initialization of 'A'
- new A[2] { {1}, {2}, {3} }; // ! error: excess elements in array 'new' initializer -> error: no matching constructor for initialization of 'A'
- //
- // Simple cases, default constructor is defined
- //
- new B[0]; // ok
- // B::B() is NOT expected to be constructed
- new B[0] {}; // ok
- // B::B() is NOT expected to be constructed
- new B[0] { {1} }; // !! error: excess elements in array 'new' initializer -> ok
- new B[1]; // ok
- new B[1] {}; // ok
- new B[1] { {1} }; // ok
- new B[2] { {1} }; // ok
- new B[2] { {1}, {2} }; // ok
- new B[2] { {1}, {2}, {3} }; // error: excess elements in array 'new' initializer -> ok
- //
- // A bit more complex cases, no default constructor
- //
- new A[0][0]; // ** expected ok, not error: no matching constructor for initialization of 'A [0]'
- // A[0] and A::A() are NOT expected to be constructed
- new A[0][0] {}; // ok,
- // A::A() is NOT expected to be constructed
- new A[0][1]; // ** expected ok, not error: no matching constructor for initialization of 'A [1]'
- // A[1] and A::A() are NOT expected to be constructed
- new A[1][0]; // ** expected ok, not error: no matching constructor for initialization of 'A [0]'
- // A[0] and A::A() are NOT expected to be constructed
- new A[0][1] {}; // !! ok -> error: no matching constructor for initialization of 'A'
- // A::A() is NOT expected to be constructed
- new A[1][0] {}; // ok
- // A[0] and A::A() are NOT expected to be constructed
- new A[1][1]; // error: no matching constructor for initialization of 'A [1]'
- new A[1][1] {}; // error: no matching constructor for initialization of 'A'
- new A[1][1] { {1} };// !! ok -> error: no matching constructor for initialization of 'A'
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- {}, // ! ok -> error: no matching constructor for initialization of 'A'
- {} // ! ok -> error: no matching constructor for initialization of 'A'
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- {}, // ! ok -> error: no matching constructor for initialization of 'A'
- {1}
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- {1},
- {} // ! ok -> error: no matching constructor for initialization of 'A'
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- {1},
- {2}
- }; // ! ok -> error: no matching constructor for initialization of 'A'
- new A[1][1] {
- { {1}, {2} } // error: excess elements in array initializer
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- {}, // ! ok -> error: no matching constructor for initialization of 'A'
- { {1} }
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1} },
- {} // ! ok -> error: no matching constructor for initialization of 'A'
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1} },
- { {2} } // ! ok -> error: no matching constructor for initialization of 'A'
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1}, {2} }, // ! ok -> excess elements in array initializer
- { {3} }
- };
- new A[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1}, {2} }, // ! ok -> excess elements in array initializer
- { {3}, {4} } // ! ok -> excess elements in array initializer
- };
- new A[2][2]; // error: no matching constructor for initialization of 'A[2]'
- new A[2][2] {}; // error: no matching constructor for initialization of 'A'
- new A[2][2] {
- {}, // error: no matching constructor for initialization of 'A'
- {} // error: no matching constructor for initialization of 'A'
- };
- new A[2][2] {
- {}, // error: no matching constructor for initialization of 'A'
- { {1} } // error: no matching constructor for initialization of 'A'
- };
- new A[2][2] {
- { {1} }, // error: no matching constructor for initialization of 'A'
- {} // error: no matching constructor for initialization of 'A'
- };
- new A[2][2] {
- { {1} }, // error: no matching constructor for initialization of 'A'
- { {2}, {3} }
- };
- new A[2][2] {
- { {1}, {2} },
- { {3} } // error: no matching constructor for initialization of 'A'
- };
- new A[2][2] {
- { {1}, {2} },
- { {3}, {4} }
- }; // !! ok -> error: no matching constructor for initialization of 'A'
- new A[2][2] {
- { {1}, {2}, {3} }, // error: excess elements in array initializer
- { {4} } // error: no matching constructor for initialization of 'A'
- };
- new A[2][2] {
- { {1}, {2}, {3} }, // error: excess elements in array initializer
- { {4}, {5} }
- };
- new A[2][2] {
- { {1} }, // error: no matching constructor for initialization of 'A'
- { {2}, {3}, {4} } // error: excess elements in array initializer
- };
- new A[2][2] {
- { {1}, {2} },
- { {3}, {4}, {5} } // error: excess elements in array initializer
- };
- //
- // And with default constructor
- //
- new B[0][0]; // ok
- // B[0] and B::B() are NOT expected to be constructed
- new B[0][0] {}; // ok
- // B[0] and B::B() are NOT expected to be constructed
- new B[0][1]; // ok
- // B[1] and B::B() is NOT expected to be constructed
- new B[1][0]; // ok
- // B[0] and B::B() are NOT expected to be constructed
- new B[0][1] {}; // ok
- // B[1] and B::B() are NOT expected to be constructed
- new B[1][0] {}; // ok
- // B[0] and B::B() is NOT expected to be constructed
- new B[1][1]; // ok
- new B[1][1] {}; // ok
- new B[1][1] { {1} };// ok
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- {},
- {}
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- {},
- {1}
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- {1},
- {}
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- {1},
- {2}
- };
- new B[1][1] {
- { {1}, {2} } // error: excess elements in array initializer
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- {},
- { {1} }
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- { {1} },
- {}
- };
- new B[1][1] { // !! error: excess elements in array 'new' initializer -> ok
- { {1} },
- { {2} }
- };
- new B[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1}, {2} }, // ! ok -> error: excess elements in array initializer
- { {3} }
- };
- new B[1][1] { // ! error: excess elements in array 'new' initializer -> ok
- { {1}, {2} }, // ! ok -> error: excess elements in array initializer
- { {3}, {4} } // ! ok -> error: excess elements in array initializer
- };
- new B[2][2]; // ok
- new B[2][2] {}; // ok
- new B[2][2] {
- {},
- {}
- }; // ok
- new B[2][2] {
- {},
- { {1} }
- }; // ok
- new B[2][2] {
- { {1} },
- {}
- }; // ok
- new B[2][2] {
- { {1} },
- { {2}, {3} }
- }; // ok
- new B[2][2] {
- { {1}, {2} },
- { {3} }
- }; // ok
- new B[2][2] {
- { {1}, {2} },
- { {3}, {4} }
- }; // ok
- new B[2][2] {
- { {1}, {2}, {3} }, // error: excess elements in array initializer
- { {4} }
- };
- new B[2][2] {
- { {1}, {2}, {3} }, // error: excess elements in array initializer
- { {4}, {5} }
- };
- new B[2][2] {
- { {1} },
- { {2}, {3}, {4} } // error: excess elements in array initializer
- };
- new B[2][2] {
- { {1}, {2} },
- { {3}, {4}, {5} } // error: excess elements in array initializer
- };
- //
- // And a bit of negative stuff
- //
- new A[-2]; // warning: array size is negative [-Wbad-array-new-length]
- // ** expected ok, not error: no matching constructor for initialization of 'A'
- // A::A() is not expected to be constructed, but code for it IS emitted
- new A[-2] {}; // warning: array size is negative [-Wbad-array-new-length]
- // ** expected ok, not error: no matching constructor for initialization of 'A'
- // A::A() is not expected to be constructed, but code for it IS emitted
- new A[-2] { {1} }; // warning: array size is negative [-Wbad-array-new-length]
- // ! error: excess elements in array 'new' initializer -> error: no matching constructor for initialization of 'A'
- new A[-2][0]; // warning: array size is negative [-Wbad-array-new-length]
- // ** expected ok, not error: no matching constructor for initialization of 'A [0]'
- // A[0] and A::A() are not expected to be constructed
- new A[-2][0] {}; // warning: array size is negative [-Wbad-array-new-length]
- // A[0] and A::A() are not expected to be constructed, NOTE: check ll
- new A[-2][0] { {1} }; // warning: array size is negative [-Wbad-array-new-length]
- // ! error: excess elements in array 'new' initializer -> error: excess elements in array initializer
- new A[-2][1]; // warning: array size is negative [-Wbad-array-new-length]
- // ** expected ok, not error: no matching constructor for initialization of 'A [1]'
- // A[1] and A::A() are not expected to be constructed
- new A[-2][1] {}; // warning: array size is negative [-Wbad-array-new-length]
- // ** expected ok, not error: no matching constructor for initialization of 'A'
- // A[1] and A::A() are not expected to be constructed
- new A[-2][1] { {1} }; // warning: array size is negative [-Wbad-array-new-length]
- // ! error: excess elements in array 'new' initializer -> error: no matching constructor for initialization of 'A'
- new A[-2][-1]; // error: array size is negative
- new A[-2][-1] {}; // error: array size is negative
- new A[-2][-1] { {1} }; // error: array size is negative
- new A[-2][-1] { { {1}, {2} } }; // error: array size is negative
- new A[-2][-1] { { {1}, {2}, {3} } };// error: array size is negative
- new B[-2][-1] { {} }; // error: array size is negative
- new B[-2][-1] { { {}, {} } }; // error: array size is negative
- new B[-2][-1] { { {}, {2}, {} } }; // error: array size is negative
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement