From 97ba5b86a3c7afba4e53b84d40e056328c5ba5e0 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 20 Dec 2019 23:25:44 +0000 Subject: [PATCH] PR c++/92974 - bogus location for enum and non-enum in ?: warning. build_min_non_dep wasn't setting any location so when we were emitting the warning in the following test while instantiating a template, its location was UNKNOWN_LOCATION. Rather than adding a location_t parameter, let's use the location from the original expression. * tree.c (build_min_non_dep): Use the location of NON_DEP when building the expression. * g++.dg/diagnostic/enum1.C: New test. * g++.dg/gomp/loop-2.C: Adjust dg-error. * g++.dg/gomp/for-21.C: Likewise. From-SVN: r279685 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/tree.c | 1 + gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/diagnostic/enum1.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/gomp/for-21.C | 4 ++-- gcc/testsuite/g++.dg/gomp/loop-2.C | 32 ++++++++++++++++---------------- 6 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/enum1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b72121c..1552b3e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-12-19 Marek Polacek + + PR c++/92974 - bogus location for enum and non-enum in ?: warning. + * tree.c (build_min_non_dep): Use the location of NON_DEP when + building the expression. + 2019-12-20 Jakub Jelinek PR c++/92965 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index eb3e87f..df2470a 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3356,6 +3356,7 @@ build_min_non_dep (enum tree_code code, tree non_dep, ...) non_dep = TREE_OPERAND (non_dep, 0); t = make_node (code); + SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep)); length = TREE_CODE_LENGTH (code); TREE_TYPE (t) = unlowered_expr_type (non_dep); TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9913e8a..a7835db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-12-19 Marek Polacek + + PR c++/92974 - bogus location for enum and non-enum in ?: warning. + * g++.dg/diagnostic/enum1.C: New test. + * g++.dg/gomp/loop-2.C: Adjust dg-error. + * g++.dg/gomp/for-21.C: Likewise. + 2019-12-20 Jakub Jelinek PR c++/92965 diff --git a/gcc/testsuite/g++.dg/diagnostic/enum1.C b/gcc/testsuite/g++.dg/diagnostic/enum1.C new file mode 100644 index 0000000..e91e970 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/enum1.C @@ -0,0 +1,14 @@ +// PR c++/92974 - bogus location for enum and non-enum in ?: warning. +// { dg-options "-Wextra" } + +enum { X }; + +struct S { + template + void f(T) { unsigned int g(X ?: g); } // { dg-warning "enumerated and non-enumerated type in conditional expression" } +}; + +struct S2 { + S m; + void l() { m.f(1); } +}; diff --git a/gcc/testsuite/g++.dg/gomp/for-21.C b/gcc/testsuite/g++.dg/gomp/for-21.C index 774f888..fbdaa71 100644 --- a/gcc/testsuite/g++.dg/gomp/for-21.C +++ b/gcc/testsuite/g++.dg/gomp/for-21.C @@ -34,8 +34,8 @@ void f4 (int a[10][10]) { #pragma omp for collapse (2) - for (int i = 0; i < 10; ++i) // { dg-error "initializer expression refers to iteration variable 'i'" } - for (auto j : a[i]) + for (int i = 0; i < 10; ++i) + for (auto j : a[i]) // { dg-error "initializer expression refers to iteration variable 'i'" } ; } diff --git a/gcc/testsuite/g++.dg/gomp/loop-2.C b/gcc/testsuite/g++.dg/gomp/loop-2.C index f05a8cb..9deeaa5 100644 --- a/gcc/testsuite/g++.dg/gomp/loop-2.C +++ b/gcc/testsuite/g++.dg/gomp/loop-2.C @@ -87,16 +87,16 @@ f1 (int x) for (j = baz (&i); j < 16; j += 2) /* { dg-error "initializer expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 16; j > (i & x); j--) + for (i = 0; i < 16; i++) + for (j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < i; j++) + for (i = 0; i < 16; i++) + for (j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < i + 4; j++) + for (i = 0; i < 16; i++) + for (j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (i = 0; i < j + 4; i++) /* { dg-error "condition expression refers to iteration variable" } */ @@ -111,8 +111,8 @@ f1 (int x) for (j = 0; j < 16; j++) ; #pragma omp for collapse(2) - for (i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (j = 0; j < baz (&i); j++) + for (i = 0; i < 16; i++) + for (j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (i = 0; i < 16; i += j) /* { dg-error "increment expression refers to iteration variable" } */ @@ -221,20 +221,20 @@ f2 (int x) for (int j = baz (&i); j < 16; j += 2) /* { dg-error "initializer expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 16; j > (i & x); j--) + for (int i = 0; i < 16; i++) + for (int j = 16; j > (i & x); j--) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < i; j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < i; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < i + 4; j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < i + 4; j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) - for (int i = 0; i < 16; i++) /* { dg-error "condition expression refers to iteration variable" } */ - for (int j = 0; j < baz (&i); j++) + for (int i = 0; i < 16; i++) + for (int j = 0; j < baz (&i); j++) /* { dg-error "condition expression refers to iteration variable" } */ ; #pragma omp for collapse(2) for (int i = 0; i < 16; i++) /* { dg-error "increment expression refers to iteration variable" } */ -- 2.7.4