From: Marek Polacek Date: Fri, 29 Jun 2018 15:25:14 +0000 (+0000) Subject: re PR c++/86184 (Conditional expression with omitted operand cannot use rvalue of... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dd2a449867efaef1d2daceadab823d638a7dabcf;p=gcc.git re PR c++/86184 (Conditional expression with omitted operand cannot use rvalue of type convertible to bool) PR c++/86184 * tree.c (cp_save_expr): Don't call save_expr for TARGET_EXPRs. * g++.dg/ext/cond3.C: New test. From-SVN: r262254 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 906f0b41678..556b154b14e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-06-29 Marek Polacek + + PR c++/86184 + * tree.c (cp_save_expr): Don't call save_expr for TARGET_EXPRs. + 2018-06-28 David Malcolm * parser.c (cp_parser_error_1): After issuing a conflict marker diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index e7bd79b6276..361248d4b52 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -4918,6 +4918,11 @@ cp_save_expr (tree expr) tree codes. */ if (processing_template_decl) return expr; + + /* TARGET_EXPRs are only expanded once. */ + if (TREE_CODE (expr) == TARGET_EXPR) + return expr; + return save_expr (expr); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9072c6d5dd6..cc71d594739 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-29 Marek Polacek + + PR c++/86184 + * g++.dg/ext/cond3.C: New test. + 2018-06-29 Kyrylo Tkachov * gcc.target/arm/arm-soft-strd-even.c: New test. diff --git a/gcc/testsuite/g++.dg/ext/cond3.C b/gcc/testsuite/g++.dg/ext/cond3.C new file mode 100644 index 00000000000..6390dc4270b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/cond3.C @@ -0,0 +1,20 @@ +// PR c++/86184 +// { dg-do run } +// { dg-options "" } + +int j; +struct X { + X() { j++; } + operator bool() { return true; } +}; + +/* Only create X once. */ +bool b = X() ?: false; +bool b2 = X() ? X() : false; + +int +main () +{ + if (j != 3) + __builtin_abort (); +}