* [C++ PATCH] Adjust -Wsequence-point for C++17 changes (PR c++/91415)
@ 2019-08-12 14:53 Jakub Jelinek
2019-08-12 20:15 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-08-12 14:53 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
The following patch adds some tweaks for -Wsequence-point warning for C++17
and later. In particular, stop warning about no sequence point in between
<<, >>, ., -> and [] expressions, where E1 is in C++17 sequenced before E2.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
As mentioned in the PR, this is just part of the needed changes, I've tried
to adjust handling of MODIFY_EXPR, but didn't figure out exactly what needs
to be done, and .* / ->* aren't handled either, and CALL_EXPR needs probably
some verification too.
2019-08-12 Jakub Jelinek <jakub@redhat.com>
PR c++/91415
* c-common.c (verify_tree): For LSHIFT_EXPR, RSHIFT_EXPR,
COMPONENT_REF and ARRAY_REF in cxx_dialect >= cxx17 mode handle it
like COMPOUND_EXPR rather than normal expression.
* g++.dg/warn/sequence-pt-4.C: New test.
--- gcc/c-family/c-common.c.jj 2019-08-12 09:45:54.463491950 +0200
+++ gcc/c-family/c-common.c 2019-08-12 12:01:32.783135654 +0200
@@ -1889,6 +1889,7 @@ verify_tree (tree x, struct tlist **pbef
case COMPOUND_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
+ sequenced_binary:
tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
warn_for_collisions (tmp_nosp);
@@ -2031,8 +2035,18 @@ verify_tree (tree x, struct tlist **pbef
x = TREE_OPERAND (x, 0);
goto restart;
}
- gcc_fallthrough ();
+ goto do_default;
+
+ case LSHIFT_EXPR:
+ case RSHIFT_EXPR:
+ case COMPONENT_REF:
+ case ARRAY_REF:
+ if (cxx_dialect >= cxx17)
+ goto sequenced_binary;
+ goto do_default;
+
default:
+ do_default:
/* For other expressions, simply recurse on their operands.
Manual tail recursion for unary expressions.
Other non-expressions need not be processed. */
--- gcc/testsuite/g++.dg/warn/sequence-pt-4.C.jj 2019-08-12 12:16:27.205660149 +0200
+++ gcc/testsuite/g++.dg/warn/sequence-pt-4.C 2019-08-12 12:22:07.540530959 +0200
@@ -0,0 +1,21 @@
+/* More sequence point warning tests */
+/* { dg-do compile } */
+/* { dg-options "-Wsequence-point" } */
+
+struct S { int a[10]; };
+void bar (int, int, int, int, int, int, int, int);
+
+int
+foo (int i, int x[10][10], int y[10], struct S z[10], struct S *w[10])
+{
+ int b = x[i++][i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
+ int c = i++ << i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
+ int d = i++ >> i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
+ int e = i++ && i++;
+ int f = i++ ? i++ : i++;
+ int g = (i++, i++);
+ int h = z[i++].a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
+ int j = w[i++]->a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */
+ bar (b, c, d, e, f,g, h, j);
+ return i;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Adjust -Wsequence-point for C++17 changes (PR c++/91415)
2019-08-12 14:53 [C++ PATCH] Adjust -Wsequence-point for C++17 changes (PR c++/91415) Jakub Jelinek
@ 2019-08-12 20:15 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2019-08-12 20:15 UTC (permalink / raw)
To: Jakub Jelinek, Jason Merrill; +Cc: gcc-patches
On 8/12/19 8:48 AM, Jakub Jelinek wrote:
> Hi!
>
> The following patch adds some tweaks for -Wsequence-point warning for C++17
> and later. In particular, stop warning about no sequence point in between
> <<, >>, ., -> and [] expressions, where E1 is in C++17 sequenced before E2.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> As mentioned in the PR, this is just part of the needed changes, I've tried
> to adjust handling of MODIFY_EXPR, but didn't figure out exactly what needs
> to be done, and .* / ->* aren't handled either, and CALL_EXPR needs probably
> some verification too.
>
> 2019-08-12 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/91415
> * c-common.c (verify_tree): For LSHIFT_EXPR, RSHIFT_EXPR,
> COMPONENT_REF and ARRAY_REF in cxx_dialect >= cxx17 mode handle it
> like COMPOUND_EXPR rather than normal expression.
>
> * g++.dg/warn/sequence-pt-4.C: New test.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-12 20:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 14:53 [C++ PATCH] Adjust -Wsequence-point for C++17 changes (PR c++/91415) Jakub Jelinek
2019-08-12 20:15 ` Jeff Law
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).