cxx0x-initializer-references.cpp [plain text]
struct one { char c; };
struct two { char c[2]; };
namespace reference {
struct A {
int i1, i2;
};
void single_init() {
const int &cri1a = {1};
const int &cri1b{1};
int i = 1;
int &ri1a = {i};
int &ri1b{i};
int &ri2 = {1};
A a{1, 2};
A &ra1a = {a};
A &ra1b{a};
}
void reference_to_aggregate() {
const A &ra1{1, 2};
A &ra2{1, 2};
const int (&arrayRef)[] = {1, 2, 3};
static_assert(sizeof(arrayRef) == 3 * sizeof(int), "bad array size");
}
struct B {
int i1;
};
void call() {
void f(const int&);
f({1});
void g(int&); g({1}); int i = 0;
g({i});
void h(const B&);
h({1});
void a(B&); a({1}); B b{1};
a({b});
}
void overloading() {
one f(const int&);
two f(const B&);
static_assert(sizeof(f({1})) == sizeof(one), "bad overload resolution");
one g(int&);
two g(const B&);
static_assert(sizeof(g({1})) == sizeof(two), "bad overload resolution");
one h(const int&);
two h(const A&);
static_assert(sizeof(h({1, 2})) == sizeof(two), "bad overload resolution");
}
void edge_cases() {
int const &b({0}); }
}
namespace PR12182 {
void f(int const(&)[3]);
void g() {
f({1, 2});
}
}
namespace PR12660 {
const int &i { 1 };
struct S { S(int); } const &s { 2 };
}