From fc8b67411812f81151b4fa3dfcc0bd378e2d5cf8 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Sat, 31 Mar 2018 03:44:12 +0000 Subject: [PATCH] [PR c++/85027] deal with baselink in save_expr in instantiate_type We use SAVE_EXPRs in conditional expressions without the middle operand, to evaluate the first operand only once. When the conversion of the first operand fails, we may call instantiate_type get a better error message. We have code to peel off the SAVE_EXPR there, but then we may end up with a BASELINK, and we're past the code that deals with BASELINKs. Reorder the tests so that we expose the saved expr first, and then deal with BASELINKs. for gcc/cp/ChangeLog PR c++/85027 * class.c (instantiate_type): Peel off SAVE_EXPR before BASELINK. for gcc/testsuite/ChangeLog PR c++/85027 * g++.dg/pr85027.C: New. From-SVN: r258989 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/class.c | 10 +++++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/pr85027.C | 8 ++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr85027.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3ea9faa74fb..d52a0dc33a3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-31 Alexandre Oliva + + PR c++/85027 + * class.c (instantiate_type): Peel off SAVE_EXPR before + BASELINK. + 2018-03-30 Jason Merrill * typeck2.c (process_init_constructor_record): Use diff --git a/gcc/cp/class.c b/gcc/cp/class.c index debcaf21cf7..0427d1224f7 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -7971,6 +7971,11 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain) } } + /* If we instantiate a template, and it is a A ?: C expression + with omitted B, look through the SAVE_EXPR. */ + if (TREE_CODE (rhs) == SAVE_EXPR) + rhs = TREE_OPERAND (rhs, 0); + if (BASELINK_P (rhs)) { access_path = BASELINK_ACCESS_BINFO (rhs); @@ -7986,11 +7991,6 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain) return error_mark_node; } - /* If we instantiate a template, and it is a A ?: C expression - with omitted B, look through the SAVE_EXPR. */ - if (TREE_CODE (rhs) == SAVE_EXPR) - rhs = TREE_OPERAND (rhs, 0); - /* There are only a few kinds of expressions that may have a type dependent on overload resolution. */ gcc_assert (TREE_CODE (rhs) == ADDR_EXPR diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 16ffbd6d963..d3044eac963 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-31 Alexandre Oliva + + PR c++/85027 + * g++.dg/pr85027.C: New. + 2018-03-31 Segher Boessenkool PR target/83315 diff --git a/gcc/testsuite/g++.dg/pr85027.C b/gcc/testsuite/g++.dg/pr85027.C new file mode 100644 index 00000000000..01b1b291aec --- /dev/null +++ b/gcc/testsuite/g++.dg/pr85027.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +// Avoid -pedantic-error default +// { dg-options "" } + +struct A { static int a; }; + +int t = A::A ? : 0; // { dg-error "cannot resolve" } -- 2.30.2