// Drop reference. Intentionally without qualifier change.
char***var5=cppp(var4);
constintar[100]={0};
// Array decay. Intentionally without qualifier change.
typedefint*intp;
int*pi=intp(ar);
ffp=0;
// Don't misidentify fn** as a function pointer.
typedeff*fp_t;
f*fpp=fp_t(&fp);
intconstA::*constA::*icapcap=0;
typedefintA::*A::*iapap_t;
iapap_tiapap=iapap_t(icapcap);
}
// ----------- static_cast -------------
structB:publicA{};// Single public base.
structC1:publicvirtualB{};// Single virtual base.
structC2:publicvirtualB{};
structD:publicC1,publicC2{};// Diamond
structE:privateA{};// Single private base.
structF:publicC1{};// Single path to B with virtual.
structG1:publicB{};
structG2:publicB{};
structH:publicG1,publicG2{};// Ambiguous path to B.
enumEnum{En1,En2};
enumOnom{On1,On2};
structCo1{operatorint();};
structCo2{Co2(int);};
structCo3{};
structCo4{Co4(Co3);operatorCo3();};
// Explicit implicits
voidt_529_2()
{
inti=1;
(void)float(i);
doubled=1.0;
(void)float(d);
(void)int(d);
(void)char(i);
typedefunsignedlongulong;
(void)ulong(i);
(void)int(En1);
(void)double(En1);
typedefint&intr;
(void)intr(i);
typedefconstint&cintr;
(void)cintr(i);
intar[1];
typedefconstint*cintp;
(void)cintp(ar);
typedefvoid(*pfvv)();
(void)pfvv(t_529_2);
typedefvoid*voidp;
(void)voidp(0);
(void)voidp((int*)0);
typedefvolatileconstvoid*vcvoidp;
(void)vcvoidp((constint*)0);
typedefA*Ap;
(void)Ap((B*)0);
typedefA&Ar;
(void)Ar(*((B*)0));
typedefconstB*cBp;
(void)cBp((C1*)0);
typedefB&Br;
(void)Br(*((C1*)0));
(void)Ap((D*)0);
typedefconstA&cAr;
(void)cAr(*((D*)0));
typedefintB::*Bmp;
(void)Bmp((intA::*)0);
typedefvoid(B::*Bmfp)();
(void)Bmfp((void(A::*)())0);
(void)Ap((E*)0);// functional-style cast ignores access control
(void)voidp((constint*)0);// const_cast appended
(void)int(Co1());
(void)Co2(1);
(void)Co3((Co4)(Co3()));
// Bad code below
//(void)(A*)((H*)0); // {{static_cast from 'struct H *' to 'struct A *' is not allowed}}
}
// Anything to void
voidt_529_4()
{
void(1);
(void(t_529_4));
}
// Static downcasts
voidt_529_5_8()
{
typedefB*Bp;
(void)Bp((A*)0);
typedefB&Br;
(void)Br(*((A*)0));
typedefconstG1*cG1p;
(void)cG1p((A*)0);
typedefconstG1&cG1r;
(void)cG1r(*((A*)0));
(void)Bp((constA*)0);// const_cast appended
(void)Br(*((constA*)0));// const_cast appended
typedefE*Ep;
(void)Ep((A*)0);// access control ignored
typedefE&Er;
(void)Er(*((A*)0));// access control ignored
// Bad code below
typedefC1*C1p;
(void)C1p((A*)0);// expected-error {{cannot cast 'struct A *' to 'C1p' (aka 'struct C1 *') via virtual base 'struct B'}}
typedefC1&C1r;
(void)C1r(*((A*)0));// expected-error {{cannot cast 'struct A' to 'C1r' (aka 'struct C1 &') via virtual base 'struct B'}}
typedefD*Dp;
(void)Dp((A*)0);// expected-error {{cannot cast 'struct A *' to 'Dp' (aka 'struct D *') via virtual base 'struct B'}}
typedefD&Dr;
(void)Dr(*((A*)0));// expected-error {{cannot cast 'struct A' to 'Dr' (aka 'struct D &') via virtual base 'struct B'}}
typedefH*Hp;
(void)Hp((A*)0);// expected-error {{ambiguous cast from base 'struct A' to derived 'struct H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}}
typedefH&Hr;
(void)Hr(*((A*)0));// expected-error {{ambiguous cast from base 'struct A' to derived 'struct H':\n struct A -> struct B -> struct G1 -> struct H\n struct A -> struct B -> struct G2 -> struct H}}
// TODO: Test DR427. This requires user-defined conversions, though.
}
// Enum conversions
voidt_529_7()
{
(void)Enum(1);
(void)Enum(1.0);
(void)Onom(En1);
// Bad code below
(void)Enum((int*)0);// expected-error {{functional-style cast from 'int *' to 'enum Enum' is not allowed}}
}
// Void pointer to object pointer
voidt_529_10()
{
typedefint*intp;
(void)intp((void*)0);
typedefconstA*cAp;
(void)cAp((void*)0);
(void)intp((constvoid*)0);// const_cast appended
}
// Member pointer upcast.
voidt_529_9()
{
typedefintA::*Amp;
(void)Amp((intB::*)0);
// Bad code below
(void)Amp((intH::*)0);// expected-error {{ambiguous conversion from pointer to member of derived class 'struct H'}}
(void)Amp((intF::*)0);// expected-error {{conversion from pointer to member of class 'struct F'}}
}
// -------- reinterpret_cast -----------
enumtest{testval=1};
structstructure{intm;};
typedefvoid(*fnptr)();
// Test conversion between pointer and integral types, as in p3 and p4.
voidintegral_conversion()
{
typedefvoid*voidp;
void*vp=voidp(testval);
longl=long(vp);
typedeffloat*floatp;
(void)floatp(l);
fnptrfnp=fnptr(l);
(void)char(fnp);// expected-error {{cast from pointer to smaller type 'char' loses information}}
(void)intr(&c);// expected-error {{functional-style cast from rvalue to reference type 'intr' (aka 'int &')}}
}
voidmemptrs()
{
constintstructure::*psi=0;
typedefconstfloatstructure::*structurecfmp;
(void)structurecfmp(psi);
typedefintstructure::*structureimp;
(void)structureimp(psi);// const_cast appended
void(structure::*psf)()=0;
typedefint(structure::*structureimfp)();
(void)structureimfp(psf);
typedefvoid(structure::*structurevmfp)();
(void)structurevmfp(psi);// expected-error {{functional-style cast from 'int const struct structure::*' to 'structurevmfp' (aka 'void (struct structure::*)()') is not allowed}}
(void)structureimp(psf);// expected-error {{functional-style cast from 'void (struct structure::*)()' to 'structureimp' (aka 'int struct structure::*') is not allowed}}
}
// ---------------- misc ------------------
voidcrash_on_invalid_1()
{
typedefitnTypo;// expected-error {{unknown type name 'itn'}}