8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-array19.C
Martin Sebor 187c6369c0 PR c++/89974 - ICE on a definition of a non-type specialization on a struct object with pointer to member function
PR c++/89974 - ICE on a definition of a non-type specialization on a struct object with pointer to member function
PR c++/89878 - same specializations on a zero-initialized struct object as a non-type parameter treated as distinct
PR c++/89833 - sorry, unimplemented: string literal in function template signature
PR c++/47488 - sorry, unimplemented: string literal in function template signature

gcc/cp/ChangeLog:

	PR c++/89974
	PR c++/89878
	PR c++/89833
	PR c++/47488
	* decl.c (reshape_init_array_1): Strip trailing zero-initializers
	from arrays of trivial type and known size.
	* mangle.c (write_expression): Convert braced initializer lists
	to STRING_CSTs.
	(write_expression): Trim trailing zero-initializers from arrays
	of trivial type.
	(write_template_arg_literal): Mangle strings the same as braced
	initializer lists.

gcc/testsuite/ChangeLog:

	PR c++/89974
	PR c++/89878
	PR c++/89833
	PR c++/47488
	* gcc/testsuite/g++.dg/abi/mangle69.C: New test.
	* gcc/testsuite/g++.dg/abi/mangle70.C: New test.
	* gcc/testsuite/g++.dg/abi/mangle71.C: New test.
	* gcc/testsuite/g++.dg/abi/mangle72.C: New test.
	* gcc/testsuite/g++.dg/cpp0x/constexpr-array19.C: New test.
	* gcc/testsuite/g++.dg/cpp2a/nontype-class15.C: New test.
	* gcc/testsuite/g++.dg/cpp2a/nontype-class16.C: New test.
	* gcc/testsuite/g++.dg/init/array51.C: New test.

From-SVN: r270155
2019-04-04 17:10:23 -06:00

138 lines
3.8 KiB
C

// PR c++/89833
// Test to verify that constant array elements initialized to zero
// evaluate to zero regardless of the form of their initilizer,
// and irrespective whether it's explicit or implicit.
// { dg-do compile { target c++11 } }
// { dg-options "-Wall" }
static const char all_zero[1024] = { };
namespace test_int
{
constexpr int a[][3] = { { 0, 0 }, { 0 }, { } };
static_assert (sizeof a == sizeof (int) * 3 * 3);
static_assert ( a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0
&& a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0
&& a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0);
constexpr int b[3][3] = { { 0, 0 }, { 0 } };
static_assert (sizeof b == sizeof (int) * 3 * 3);
static_assert ( b[0][0] == 0 && b[0][1] == 0 && b[0][2] == 0
&& b[1][0] == 0 && b[1][1] == 0 && b[1][2] == 0
&& b[2][0] == 0 && b[2][1] == 0 && b[2][2] == 0);
constexpr int c[3][3] = { { } };
static_assert (sizeof c == sizeof (int) * 3 * 3);
static_assert ( c[0][0] == 0 && c[0][1] == 0 && c[0][2] == 0
&& c[1][0] == 0 && c[1][1] == 0 && c[1][2] == 0
&& c[2][0] == 0 && c[2][1] == 0 && c[2][2] == 0);
}
namespace test_char
{
constexpr char a[][3] = { { 0, 0 }, { 0 }, { } };
static_assert (sizeof a == sizeof (char) * 3 * 3);
static_assert ( a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0
&& a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0
&& a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0);
constexpr char b[3][3] = { { 0, 0 }, { 0 } };
static_assert (sizeof b == sizeof (char) * 3 * 3);
static_assert ( b[0][0] == 0 && b[0][1] == 0 && b[0][2] == 0
&& b[1][0] == 0 && b[1][1] == 0 && b[1][2] == 0
&& b[2][0] == 0 && b[2][1] == 0 && b[2][2] == 0);
constexpr char c[3][3] = { { } };
static_assert (sizeof c == sizeof (char) * 3 * 3);
static_assert ( c[0][0] == 0 && c[0][1] == 0 && c[0][2] == 0
&& c[1][0] == 0 && c[1][1] == 0 && c[1][2] == 0
&& c[2][0] == 0 && c[2][1] == 0 && c[2][2] == 0);
}
namespace test_string
{
constexpr char a[][3] = { "\0", "", { } };
static_assert (sizeof a == sizeof (char) * 3 * 3);
static_assert ( a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0
&& a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0
&& a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0);
constexpr char b[3][3] = { "\0", "" };
static_assert (sizeof b == sizeof (char) * 3 * 3);
static_assert ( b[0][0] == 0 && b[0][1] == 0 && b[0][2] == 0
&& b[1][0] == 0 && b[1][1] == 0 && b[1][2] == 0
&& b[2][0] == 0 && b[2][1] == 0 && b[2][2] == 0);
constexpr char c[3][3] = { };
static_assert (sizeof c == sizeof (char) * 3 * 3);
static_assert ( c[0][0] == 0 && c[0][1] == 0 && c[0][2] == 0
&& c[1][0] == 0 && c[1][1] == 0 && c[1][2] == 0
&& c[2][0] == 0 && c[2][1] == 0 && c[2][2] == 0);
}
namespace test_string_member
{
struct B { struct A { char a[5]; } a[2]; };
constexpr B b[3] =
{
/* [0] */
{
/* a = */
{
/* a[0] */ { { 0, 0, 0, 0, 0 } },
/* a[1] */ { { 0, 0 } }
}
},
/* [1] */
{
/* a */
{
/* a[0] */ { "\0\0\0\0" },
/* a[0] */ { "" }
}
},
};
static_assert ( b[0].a[0].a[0] == 0
&& b[0].a[0].a[1] == 0
&& b[0].a[0].a[2] == 0
&& b[0].a[0].a[3] == 0
&& b[0].a[0].a[4] == 0
&& b[0].a[1].a[0] == 0
&& b[0].a[1].a[1] == 0
&& b[0].a[1].a[2] == 0
&& b[0].a[1].a[3] == 0
&& b[0].a[1].a[4] == 0
&& b[1].a[0].a[0] == 0
&& b[1].a[0].a[1] == 0
&& b[1].a[0].a[2] == 0
&& b[1].a[0].a[3] == 0
&& b[1].a[0].a[4] == 0
&& b[2].a[0].a[0] == 0
&& b[2].a[0].a[1] == 0
&& b[2].a[0].a[2] == 0
&& b[2].a[0].a[3] == 0
&& b[2].a[0].a[4] == 0);
}