diff options
author | Marek Polacek <polacek@redhat.com> | 2018-01-10 17:05:14 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2018-01-10 17:05:14 +0000 |
commit | 6bebae75035889a4844eb4d32a695bebf412bcd7 (patch) | |
tree | 37f7d206934485b75f5cdcabfcc92b8619d89cbd /gcc | |
parent | e99ef40892b598eeb3fa496cc472e111675d7f6c (diff) | |
download | gcc-6bebae75035889a4844eb4d32a695bebf412bcd7.zip gcc-6bebae75035889a4844eb4d32a695bebf412bcd7.tar.gz gcc-6bebae75035889a4844eb4d32a695bebf412bcd7.tar.bz2 |
re PR c++/82541 (Wduplicated-branches triggers in template context)
PR c++/82541
* call.c (build_conditional_expr_1): Check complain before warning.
* pt.c (tsubst_copy_and_build) <case COND_EXPR>: Suppress
-Wduplicated-branches.
* g++.dg/warn/Wduplicated-branches4.C: New test.
From-SVN: r256441
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/call.c | 1 | ||||
-rw-r--r-- | gcc/cp/pt.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C | 16 |
5 files changed, 30 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3cce212..d664bd2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-01-10 Marek Polacek <polacek@redhat.com> + + PR c++/82541 + * call.c (build_conditional_expr_1): Check complain before warning. + * pt.c (tsubst_copy_and_build) <case COND_EXPR>: Suppress + -Wduplicated-branches. + 2018-01-10 Jakub Jelinek <jakub@redhat.com> PR c++/81327 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 515e460..87bbf3c 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5345,6 +5345,7 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, /* If the ARG2 and ARG3 are the same and don't have side-effects, warn here, because the COND_EXPR will be turned into ARG2. */ if (warn_duplicated_branches + && (complain & tf_warning) && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0))) warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches, "this condition has identical branches"); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2fb327a..2deccd8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17846,6 +17846,7 @@ tsubst_copy_and_build (tree t, exp2 = RECUR (TREE_OPERAND (t, 2)); } + warning_sentinel s(warn_duplicated_branches); RETURN (build_x_conditional_expr (EXPR_LOCATION (t), cond, exp1, exp2, complain)); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0bfacf0..3936188 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-10 Marek Polacek <polacek@redhat.com> + + PR c++/82541 + * g++.dg/warn/Wduplicated-branches4.C: New test. + 2018-01-10 Jakub Jelinek <jakub@redhat.com> PR c++/81327 diff --git a/gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C b/gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C new file mode 100644 index 0000000..7963c9e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wduplicated-branches4.C @@ -0,0 +1,16 @@ +// PR c++/82541 +// { dg-do compile } +// { dg-options "-Wduplicated-branches" } + +template<int N> +struct AR +{ + char a1[N > 0 ? N : 1]; // { dg-bogus "this condition has identical branches" } + char a2[N > 0 ? 1 : 1]; // { dg-warning "this condition has identical branches" } +}; + +int +main () +{ + AR<1> w; +} |