From 6a3ebcc6620cc923b8e533d6c2381db8016f3b74 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 20 Nov 2018 23:23:12 +0100 Subject: [PATCH] re PR c++/88110 (ICE (segfault) with -std=C++2a in cxx_eval_constant_expression when trying to evaluate nonoverridden "virtual ... = 0" function of a base class) PR c++/88110 * constexpr.c (cxx_eval_constant_expression) : Punt if get_base_address of ADDR_EXPR operand is not a DECL_P. * g++.dg/cpp2a/constexpr-virtual13.C: New test. From-SVN: r266329 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 3 ++- gcc/testsuite/ChangeLog | 3 +++ .../g++.dg/cpp2a/constexpr-virtual13.C | 20 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f43d9c4fea9..a5ee86e7810 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-11-20 Jakub Jelinek + + PR c++/88110 + * constexpr.c (cxx_eval_constant_expression) : Punt + if get_base_address of ADDR_EXPR operand is not a DECL_P. + 2018-11-19 Marek Polacek PR c++/87781 - detect invalid elaborated-type-specifier. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index c9e1e0cbdcb..92fd2b2d9d5 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4815,7 +4815,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, obj = cxx_eval_constant_expression (ctx, obj, lval, non_constant_p, overflow_p); /* We expect something in the form of &x.D.2103.D.2094; get x. */ - if (TREE_CODE (obj) != ADDR_EXPR) + if (TREE_CODE (obj) != ADDR_EXPR + || !DECL_P (get_base_address (TREE_OPERAND (obj, 0)))) { if (!ctx->quiet) error_at (cp_expr_loc_or_loc (t, input_location), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b810f93c9e2..9f1edcebfde 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-11-20 Jakub Jelinek + PR c++/88110 + * g++.dg/cpp2a/constexpr-virtual13.C: New test. + PR tree-optimization/87895 * gcc.dg/gomp/pr87895-1.c: New test. * gcc.dg/gomp/pr87895-2.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C new file mode 100644 index 00000000000..921df9fe7a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C @@ -0,0 +1,20 @@ +// PR c++/88110 +// { dg-do compile } + +struct A { + virtual int foo () const = 0; +}; +struct B { + virtual int bar () const = 0; + virtual int baz () const = 0; +}; +struct C : public A { }; +struct D : public C { }; +struct E : public D, public B { }; + +void +qux (const E *x) +{ + if (x->baz ()) + ; +} -- 2.30.2