This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/85045, ICE when printing RDIV_EXPR


cxx_pretty_printer::multiplicative_expression didn't handle RDIV_EXPR, so when
we tried to print a RDIV_EXPR, we printed it as a pm-expression.  That led to
printing it as a cast-expression.  That led to printing it as a
primary-expression.  That led to printing it as a multiplicative expression.
That led to printing it as a pm-expression.  That led to printing it as a
cast-expression.  That led to printing it as a primary-expression.  That led
to... a crash.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-03-23  Marek Polacek  <polacek@redhat.com>

	PR c++/85045
	* cxx-pretty-print.c (cxx_pretty_printer::multiplicative_expression):
	Handle RDIV_EXPR.

	* g++.dg/cpp0x/Wnarrowing5.C: New test.

diff --git gcc/cp/cxx-pretty-print.c gcc/cp/cxx-pretty-print.c
index ca99997f5e1..8527a326c57 100644
--- gcc/cp/cxx-pretty-print.c
+++ gcc/cp/cxx-pretty-print.c
@@ -899,11 +899,12 @@ cxx_pretty_printer::multiplicative_expression (tree e)
     case MULT_EXPR:
     case TRUNC_DIV_EXPR:
     case TRUNC_MOD_EXPR:
+    case RDIV_EXPR:
       multiplicative_expression (TREE_OPERAND (e, 0));
       pp_space (this);
       if (code == MULT_EXPR)
 	pp_star (this);
-      else if (code == TRUNC_DIV_EXPR)
+      else if (code == TRUNC_DIV_EXPR || code == RDIV_EXPR)
 	pp_slash (this);
       else
 	pp_modulo (this);
diff --git gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C
index e69de29bb2d..9acdc6b0c91 100644
--- gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C
+++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C
@@ -0,0 +1,11 @@
+// PR c++/85045
+// { dg-do compile { target c++11 } }
+
+typedef struct tt {
+  unsigned short h;
+} tt;
+
+void mainScreen(float a)
+{
+  tt numlrect = {int(100/a)}; // { dg-error "narrowing conversion" }
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]