8sa1-gcc/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual6.C
Marek Polacek bf8d83098f P1064R0 - Allowing Virtual Function Calls in Constant Expressions
P1064R0 - Allowing Virtual Function Calls in Constant Expressions
	* call.c (build_over_call): No longer check if we're outside a template
	function.
	* class.c (build_vtbl_initializer): Build vtable's constructor with
	indexes.
	* constexpr.c (cxx_eval_constant_expression): Don't ignore _vptr's
	initializer.  Handle OBJ_TYPE_REF.
	(potential_constant_expression_1): Handle OBJ_TYPE_REF.
	* decl.c (maybe_commonize_var): Bail out for any DECL_ARTIFICIAL.
	(initialize_artificial_var): Mark the variable as constexpr.
	(grokdeclarator): Change error to pedwarn.  Only warn when
	pedantic and not C++2a.

	* gimple-fold.c (gimple_get_virt_method_for_vtable): Adjust assert.

	* g++.dg/cpp0x/constexpr-virtual5.C: Adjust dg-error.
	* g++.dg/cpp2a/constexpr-virtual1.C: New test.
	* g++.dg/cpp2a/constexpr-virtual2.C: New test.
	* g++.dg/cpp2a/constexpr-virtual3.C: New test.
	* g++.dg/cpp2a/constexpr-virtual4.C: New test.
	* g++.dg/cpp2a/constexpr-virtual5.C: New test.
	* g++.dg/cpp2a/constexpr-virtual6.C: New test.
	* g++.dg/cpp2a/constexpr-virtual7.C: New test.
	* g++.dg/cpp2a/constexpr-virtual8.C: New test.
	* g++.dg/cpp2a/constexpr-virtual9.C: New test.
	* g++.dg/diagnostic/virtual-constexpr.C: Skip for C++2a.  Use
	-pedantic-errors.  Adjust dg-error.

From-SVN: r264408
2018-09-18 19:16:28 +00:00

26 lines
383 B
C

// P1064R0
// { dg-do compile }
// { dg-options "-std=c++2a" }
struct X1
{
constexpr virtual X1 const *f() const { return this; }
};
struct Y
{
int m = 0;
};
struct X2: public Y, public X1
{
constexpr virtual X2 const *f() const { return this; }
};
constexpr X1 x1;
static_assert(x1.f() == &x1);
constexpr X2 x2;
constexpr X1 const& r2 = x2;
static_assert(r2.f() == &r2);