In the testcase for PR94186, we have a SCOPE_REF with no location even though at one point it was in a cp_expr which had a location. So let's make the cp_expr constructor that takes a location apply it to the expression when possible.
Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-03-22 Jason Merrill <ja...@redhat.com> * cp-tree.h (cp_expr): When constructing from an expr and a location, call protected_set_expr_location. --- gcc/cp/cp-tree.h | 5 ++++- gcc/testsuite/g++.dg/ext/stmtexpr15.C | 2 +- gcc/testsuite/g++.dg/parse/error26.C | 2 +- gcc/testsuite/g++.dg/warn/Wnoexcept1.C | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 0783b3114f2..4e1d0f1d42e 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -59,7 +59,10 @@ public: m_value (value), m_loc (cp_expr_location (m_value)) {} cp_expr (tree value, location_t loc): - m_value (value), m_loc (loc) {} + m_value (value), m_loc (loc) + { + protected_set_expr_location (value, loc); + } /* Implicit conversions to tree. */ operator tree () const { return m_value; } diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr15.C b/gcc/testsuite/g++.dg/ext/stmtexpr15.C index 10c4886c10c..27406e1e37f 100644 --- a/gcc/testsuite/g++.dg/ext/stmtexpr15.C +++ b/gcc/testsuite/g++.dg/ext/stmtexpr15.C @@ -4,5 +4,5 @@ void foo() { int x[({ return; })]; // { dg-error "could not convert" } -// { dg-error "12:size of array .x. has non-integral" "" { target *-*-* } .-1 } +// { dg-error "9:size of array .x. has non-integral" "" { target *-*-* } .-1 } } diff --git a/gcc/testsuite/g++.dg/parse/error26.C b/gcc/testsuite/g++.dg/parse/error26.C index 95f299163e9..4005fd5025f 100644 --- a/gcc/testsuite/g++.dg/parse/error26.C +++ b/gcc/testsuite/g++.dg/parse/error26.C @@ -4,7 +4,7 @@ void foo() { if (({int c[2];})) ; // { dg-error "7:ISO C.. forbids" "7" } - // { dg-error "17:could not convert" "17" { target *-*-* } .-1 } + // { dg-error "7:could not convert" "17" { target *-*-* } .-1 } } void bar() diff --git a/gcc/testsuite/g++.dg/warn/Wnoexcept1.C b/gcc/testsuite/g++.dg/warn/Wnoexcept1.C index 93210dead04..4fac3675cf6 100644 --- a/gcc/testsuite/g++.dg/warn/Wnoexcept1.C +++ b/gcc/testsuite/g++.dg/warn/Wnoexcept1.C @@ -7,7 +7,7 @@ // We expect a warning at the declaration of construct2, since Automatic2 is // defined below; we don't expect one for construct1, because Automatic1 is // defined in the fake system header. -// { dg-warning "noexcept-expression" "" { target *-*-* } 15 } +// { dg-warning "noexcept-expression" "" { target *-*-* } 16 } class Automatic2 { public: base-commit: 07f8bcc6ea9f3c0850a56a7431d866178d5cee92 -- 2.18.1