This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ellipsis is inherited (p0136r1 supersedes this part).
struct A { A(); A(int, char, ...); };
struct B : A { using A::A; };
B b(1, 'x', 4.0, "hello"); // ok
// inherited constructor is effectively constexpr if the user-written constructor would be
struct C { C(); constexpr C(int) {} };
struct D : C { using C::C; };
constexpr D d = D(0); // ok
struct E : C { using C::C; A a; }; // expected-note {{non-literal type}}
constexpr E e = E(0); // expected-error {{non-literal type}}
// FIXME: This diagnostic is pretty bad; we should explain that the problem
// is that F::c would be initialized by a non-constexpr constructor.
struct F : C { using C::C; C c; }; // expected-note {{here}}
constexpr F f = F(0); // expected-error {{constant expression}} expected-note {{constructor inherited from base class 'C'}}
// inherited constructor is effectively deleted if the user-written constructor would be
struct G { G(int); }; // expected-note {{declared here}}
struct H : G { using G::G; G g; }; // expected-error {{cannot use constructor inherited from base class 'G'; member 'g' of 'dr1573::H' does not have a default constructor}} expected-note {{declared here}}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned b = 0b'01; // expected-error {{invalid digit 'b' in octal constant}}
unsigned x = 0x'01; // expected-error {{invalid suffix 'x'01' on integer constant}}
}
#endif
}
#if __cplusplus >= 201103L
// dr1948: yes
// FIXME: This diagnostic could be improved.
void *operator new(__SIZE_TYPE__) noexcept { return nullptr; } // expected-error{{exception specification in declaration does not match previous declaration}}
#endif
namespace dr1959 { // dr1959: 3.9
#if __cplusplus >= 201103L
struct b;
struct c;
struct a {
a() = default;
a(const a &) = delete; // expected-note 2{{deleted}}
a(const b &) = delete; // not inherited
a(c &&) = delete; // expected-note {{deleted}}
template<typename T> a(T) = delete;
};
struct b : a { // expected-note {{copy constructor of 'b' is implicitly deleted because base class 'dr1959::a' has a deleted copy constructor}}
using a::a;
};
a x;
b y = x; // expected-error {{deleted}}
b z = z; // expected-error {{deleted}}
// FIXME: It's not really clear that this matches the intent, but it's
// consistent with the behavior for assignment operators.
struct c : a {
using a::a;
c(const c &);
};
c q(static_cast<c&&>(q)); // expected-error {{call to deleted}}
#endif
}
namespace dr1968 { // dr1968: yes
static_assert(&typeid(int) == &typeid(int), ""); // expected-error{{not an integral constant expression}}
#if __cplusplus >= 201103L
static_assert(&typeid(int) == &typeid(int), ""); // expected-error{{not an integral constant expression}}
#endif
}
namespace dr1991 { // dr1991: 3.9
#if __cplusplus >= 201103L
struct A {
A(int, int) = delete;
};
struct B : A {
using A::A;
B(int, int, int = 0);
};
// FIXME: As a resolution to an open DR against P0136R1, we treat derived
// class constructors as better than base class constructors in the presence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, int N> A(const T (&)[N]); // expected-note {{candidate constructor}} expected-note {{candidate inherited constructor}}
template<typename T, int N> A(const T (&)[N], int = 0); // expected-note {{candidate constructor}} expected-note {{candidate inherited constructor}}
};
struct B : A { // expected-note 6{{candidate}}
using A::A; // expected-warning 4{{inheriting constructor does not inherit ellipsis}} expected-note 16{{candidate}} expected-note 3{{deleted constructor was inherited here}}
struct B : A { // expected-note 4{{candidate is the implicit}}
using A::A; // expected-note 19{{inherited here}}
B(void*);
};
struct C {} c;
B b0{};
// expected-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
// expected-note@-8 {{default constructor of 'B' is implicitly deleted because base class 'A' has multiple default constructors}}
A a0{}; // expected-error {{ambiguous}}
B b0{}; // expected-error {{ambiguous}}
B b1{1};
// expected-error@-1 {{call to deleted constructor of 'B'}}
A a1{1}; // expected-error {{ambiguous}}
B b1{1}; // expected-error {{ambiguous}}
B b2{1,2};
// expected-error@-1 {{call to deleted constructor of 'B'}}
A a2{1,2}; // expected-error {{ambiguous}}
B b2{1,2}; // expected-error {{ambiguous}}
B b3{1,2,3};
// ok
A a3{1,2,3}; // ok
B b3{1,2,3}; // ok
B b4{1,2,3,4};
// ok
A a4{1,2,3,4}; // ok
B b4{1,2,3,4}; // ok
B b5{1,2,3,4,5};
// expected-error@-1 {{no matching constructor for initialization of 'B'}}
A a5{1,2,3,4,5}; // ok
B b5{1,2,3,4,5}; // ok
B b6{c};
// ok
A a6{c}; // ok
B b6{c}; // ok
B b7{c,0};
// ok
A a7{c,0}; // ok
B b7{c,0}; // ok
B b8{c,0,1};
// expected-error@-1 {{no matching constructor}}
A a8{c,0,1}; // ok
B b8{c,0,1}; // ok
B b9{"foo"};
// FIXME: explain why the inheriting constructor was deleted
// expected-error@-2 {{call to deleted constructor of 'B'}}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr BothNonConstexpr bothNC{42}; // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'BothNonConstexpr(42)'}}
// FIXME: This diagnostic is not very good. We should explain that the problem is that base class NonConstexpr cannot be initialized.
struct BothNonConstexpr
: NonConstexpr,
Constexpr {
using Constexpr::Constexpr; // expected-note {{here}}
};
constexpr BothNonConstexpr bothNC{42}; // expected-error {{must be initialized by a constant expression}} expected-note {{inherited from base class 'Constexpr'}}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D1 d(2, 3, 4); // OK: B1 is initialized by calling B1(2, 3, 4),
// then d.x is default-initialized (no initialization is performed),
// then d.y is initialized by calling get()
D1 e; // expected-error {{implicitly-deleted}}
}
struct D2 : B2 {
using B2::B2; // expected-error {{cannot use constructor inherited from base class 'B2'; member 'b' of 'std_example::D2' does not have a default constructor}}
B1 b; // expected-note {{member}}
};
D2 f(1.0); // expected-note {{inherited constructor for 'D2' first required here}}
struct W {
W(int);
};
struct X : virtual W {
using W::W;
X() = delete;
};
struct Y : X {
using X::X;
};
struct Z : Y, virtual W {
using Y::Y;
};
Z z(0); // OK: initialization of Y does not invoke default constructor of X
template <class T> struct Log : T {
using T::T; // inherits all constructors from class T
struct C : B { // expected-note {{deleted default constructor}}
using B::B; // expected-error {{cannot use constructor inherited from base class 'B'; base class 'vbase::V' of 'vbase::C' does not have a default constructor}}
};
struct D : A, C { // expected-note {{deleted default constructor}}
using A::A;
using C::C; // expected-error {{cannot use constructor inherited from base class 'C'; base class 'vbase::V' of 'vbase::D' does not have a default constructor}} expected-error {{call to deleted constructor of 'vbase::A'}}
};
A a0; // expected-error {{deleted}}
A a1(0);
B b0; // expected-error {{deleted}}
B b1(0);
B b2(0, 0);
C c0; // expected-error {{deleted}}
C c1(0);
C c2(0, 0); // expected-note {{first required here}}
D d0; // expected-error {{implicitly-deleted}}
D d1(0);
D d2(0, 0); // expected-note {{first required here}}
}
namespace constexpr_init_order {
struct Param;
struct A {
constexpr A(Param);
int a;
};
struct B : A { B(); using A::A; int b = 2; };
extern const B b;
struct Param {
constexpr Param(int c) : n(4 * b.a + b.b + c) {}
int n;
};
constexpr A::A(Param p) : a(p.n) {}
constexpr B b(1);
constexpr B c(1);
static_assert(b.a == 1, "p should be initialized before B() is executed");
static_assert(c.a == 7, "b not initialzed properly");
}
namespace default_args {
// We work around a defect in P0136R1 where it would reject reasonable
// code like the following:
struct Base {
Base(int = 0);
};
struct Derived : Base {
using Base::Base;
};
Derived d;
// FIXME: Once a fix is standardized, implement it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static constexpr int j = g(static_cast<XX*>(nullptr)); // expected-error {{constexpr variable 'j' must be initialized by a constant expression}} expected-note {{undefined function 'g' cannot be used in a constant expression}}
};
}
namespace InheritedCtor {
struct A { constexpr A(int) {} };
struct B : A { int n; using A::A; }; // expected-note {{here}}
constexpr B b(0); // expected-error {{constant expression}} expected-note {{derived class}}
struct C : A { using A::A; struct { union { int n, m = 0; }; union { int a = 0; }; int k = 0; }; struct {}; union {}; }; // expected-warning 4{{extension}}
constexpr C c(0);
struct D : A {
using A::A; // expected-note {{here}}
struct { // expected-warning {{extension}}
union { // expected-warning {{extension}}
int n;
};
};
};
constexpr D d(0); // expected-error {{constant expression}} expected-note {{derived class}}
struct E : virtual A { using A::A; }; // expected-note {{here}}
// We wrap a function around this to avoid implicit zero-initialization
// happening first; the zero-initialization step would produce the same
// error and defeat the point of this test.
void f() {
constexpr E e(0); // expected-error {{constant expression}} expected-note {{derived class}}
}
// FIXME: This produces a note with no source location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters