re PR c++/85045 (ICE+SIGILL on valid C++ code: cxx_pretty_printer::postfix_expressio...
authorMarek Polacek <polacek@redhat.com>
Fri, 23 Mar 2018 13:45:49 +0000 (13:45 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 23 Mar 2018 13:45:49 +0000 (13:45 +0000)
PR c++/85045
* c-pretty-print.c (c_pretty_printer::multiplicative_expression)
<case RDIV_EXPR>: Tweak condition.

* cxx-pretty-print.c (cxx_pretty_printer::multiplicative_expression):
Handle EXACT_DIV_EXPR and RDIV_EXPR.  Tweak condition.
(cxx_pretty_printer::expression): Handle EXACT_DIV_EXPR and RDIV_EXPR.

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

From-SVN: r258804

gcc/c-family/ChangeLog
gcc/c-family/c-pretty-print.c
gcc/cp/ChangeLog
gcc/cp/cxx-pretty-print.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr85045.c [new file with mode: 0644]

index 25ed91f208943d515a9a0d60e7e9a9556b5bd8ae..f728311310a8da064b6b1f1fe1d82c6a90045444 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-23  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85045
+       * c-pretty-print.c (c_pretty_printer::multiplicative_expression)
+       <case RDIV_EXPR>: Tweak condition.
+
 2018-03-20  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-ada-spec.c (pp_ada_tree_identifier): Deal specifically with _Bool.
index c9dd8aefff9beaadf54350b0a5be99c6a45954ba..dc76c9957d3a0e0485313aef1c1eb28977a0da89 100644 (file)
@@ -1841,7 +1841,7 @@ c_pretty_printer::multiplicative_expression (tree e)
       pp_c_whitespace (this);
       if (code == MULT_EXPR)
        pp_c_star (this);
-      else if (code == TRUNC_DIV_EXPR)
+      else if (code != TRUNC_MOD_EXPR)
        pp_slash (this);
       else
        pp_modulo (this);
index e04eae18a44d097e9419b9577d76c32693163fcd..ddda091b5fda6cef0f681b3f816e143d43f14a98 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-23  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85045
+       * cxx-pretty-print.c (cxx_pretty_printer::multiplicative_expression):
+       Handle EXACT_DIV_EXPR and RDIV_EXPR.  Tweak condition.
+       (cxx_pretty_printer::expression): Handle EXACT_DIV_EXPR and RDIV_EXPR.
+
 2018-03-23  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Implement P0962
index ca99997f5e17f4456ac4161102f497f788e71967..9a5545cb5ccbea15983118c0430ef6429e3a0e9b 100644 (file)
@@ -899,11 +899,13 @@ cxx_pretty_printer::multiplicative_expression (tree e)
     case MULT_EXPR:
     case TRUNC_DIV_EXPR:
     case TRUNC_MOD_EXPR:
+    case EXACT_DIV_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_MOD_EXPR)
        pp_slash (this);
       else
        pp_modulo (this);
@@ -1113,6 +1115,8 @@ cxx_pretty_printer::expression (tree t)
     case MULT_EXPR:
     case TRUNC_DIV_EXPR:
     case TRUNC_MOD_EXPR:
+    case EXACT_DIV_EXPR:
+    case RDIV_EXPR:
       multiplicative_expression (t);
       break;
 
index 88abac8faeb57856c19d87b0971ca23e3d91eb17..fe12bbe38cef4083ccb454c733f27559132ec3c5 100644 (file)
@@ -3,6 +3,10 @@
        PR c++/85033
        * g++.dg/ext/builtin-offsetof2.C: New test.
 
+       PR c++/85045
+       * g++.dg/cpp0x/Wnarrowing5.C: New test.
+       * gcc.dg/pr85045.c: New test.
+
 2018-03-23  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR debug/85020
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C
new file mode 100644 (file)
index 0000000..d2abf03
--- /dev/null
@@ -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" }
+}
diff --git a/gcc/testsuite/gcc.dg/pr85045.c b/gcc/testsuite/gcc.dg/pr85045.c
new file mode 100644 (file)
index 0000000..8c4a7aa
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR c/85045 */
+/* { dg-do compile } */
+/* { dg-options "-fno-diagnostics-show-caret" } */
+
+void
+f (double a, double b)
+{
+  (a / b) (); /* { dg-error "called object .a / b. is not a function or function pointer" } */
+}