* [PATCH] [PR c++/85027] deal with baselink in save_expr in instantiate_type
@ 2018-03-30 7:55 Alexandre Oliva
2018-03-30 15:01 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2018-03-30 7:55 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, nathan
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.
Regstrapped on i686- and x86_64-linux-gnu. Ok to install?
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.
---
gcc/cp/class.c | 10 +++++-----
gcc/testsuite/g++.dg/pr85027.C | 8 ++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/pr85027.C
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index debcaf21cf76..0427d1224f74 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/g++.dg/pr85027.C b/gcc/testsuite/g++.dg/pr85027.C
new file mode 100644
index 000000000000..01b1b291aecd
--- /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" }
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [PR c++/85027] deal with baselink in save_expr in instantiate_type
2018-03-30 7:55 [PATCH] [PR c++/85027] deal with baselink in save_expr in instantiate_type Alexandre Oliva
@ 2018-03-30 15:01 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-03-30 15:01 UTC (permalink / raw)
To: Alexandre Oliva; +Cc: gcc-patches List, Nathan Sidwell
OK.
On Fri, Mar 30, 2018 at 3:49 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
> 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.
>
> Regstrapped on i686- and x86_64-linux-gnu. Ok to install?
>
> 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.
> ---
> gcc/cp/class.c | 10 +++++-----
> gcc/testsuite/g++.dg/pr85027.C | 8 ++++++++
> 2 files changed, 13 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/pr85027.C
>
> diff --git a/gcc/cp/class.c b/gcc/cp/class.c
> index debcaf21cf76..0427d1224f74 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/g++.dg/pr85027.C b/gcc/testsuite/g++.dg/pr85027.C
> new file mode 100644
> index 000000000000..01b1b291aecd
> --- /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" }
>
>
> --
> Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
> You must be the change you wish to see in the world. -- Gandhi
> Be Free! -- http://FSFLA.org/ FSF Latin America board member
> Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-30 14:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-30 7:55 [PATCH] [PR c++/85027] deal with baselink in save_expr in instantiate_type Alexandre Oliva
2018-03-30 15:01 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).