[gcc/devel/c++-modules] c++: Improve error recovery for =.
Nathan Sidwell
nathan@gcc.gnu.org
Wed Jun 10 16:39:55 GMT 2020
https://gcc.gnu.org/g:4f602147b6abbe05f862d3feda8290d4cf5c583f
commit 4f602147b6abbe05f862d3feda8290d4cf5c583f
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 21 10:27:11 2020 -0400
c++: Improve error recovery for =.
In a template we were happily embedding error_mark_node in a MODOP_EXPR,
leading to confusion later.
gcc/cp/ChangeLog:
* typeck.c (build_x_modify_expr): Handle error_mark_node arguments.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/lambda/lambda-ice30.C: Adjust.
* g++.dg/cpp0x/lambda/lambda-ice31.C: Adjust.
* g++.dg/ext/fixed1.C: Adjust.
* g++.dg/template/crash107.C: Adjust.
* g++.dg/template/error35.C: Adjust.
* g++.dg/template/sizeof-template-argument.C: Adjust.
Diff:
---
gcc/cp/typeck.c | 3 +++
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C | 4 ++--
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C | 2 +-
gcc/testsuite/g++.dg/ext/fixed1.C | 2 ++
gcc/testsuite/g++.dg/template/crash107.C | 4 ++--
gcc/testsuite/g++.dg/template/error35.C | 2 +-
gcc/testsuite/g++.dg/template/sizeof-template-argument.C | 4 ++--
7 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 0181984bb99..f01ae656254 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8768,6 +8768,9 @@ build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
tree overload = NULL_TREE;
tree op = build_nt (modifycode, NULL_TREE, NULL_TREE);
+ if (lhs == error_mark_node || rhs == error_mark_node)
+ return cp_expr (error_mark_node, loc);
+
if (processing_template_decl)
{
if (modifycode == NOP_EXPR
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C
index 46350bd1d52..7b0a155a31a 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice30.C
@@ -3,11 +3,11 @@
template<int> void foo()
{
- int x[=]; // { dg-error "expected" }
+ int x[=]; // { dg-error "" }
[&x]{};
}
void bar()
{
- foo<0>();
+ foo<0>(); // { dg-prune-output "not declared" }
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C
index 54ded7bb282..f0ecf8cc26f 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice31.C
@@ -4,5 +4,5 @@
template<typename T> void foo()
{
T x[=]; // { dg-error "expected" }
- [&x]{};
+ [&x]{}; // { dg-prune-output "not declared" }
}
diff --git a/gcc/testsuite/g++.dg/ext/fixed1.C b/gcc/testsuite/g++.dg/ext/fixed1.C
index 5a479d6891a..92e3184ea59 100644
--- a/gcc/testsuite/g++.dg/ext/fixed1.C
+++ b/gcc/testsuite/g++.dg/ext/fixed1.C
@@ -6,3 +6,5 @@ template<int> struct A {};
template<typename> struct B : A<sizeof(0=0r)> {}; // { dg-error "not supported" }
template<typename> struct C : A<sizeof(0=0r)> {}; // { dg-error "not supported" }
+
+// { dg-prune-output "template argument" }
diff --git a/gcc/testsuite/g++.dg/template/crash107.C b/gcc/testsuite/g++.dg/template/crash107.C
index 932a3a68059..aab882d8446 100644
--- a/gcc/testsuite/g++.dg/template/crash107.C
+++ b/gcc/testsuite/g++.dg/template/crash107.C
@@ -10,9 +10,9 @@ template<typename FP_> struct Vec { // { dg-message "note" "" { target c++17_dow
X = y*rhs.z() - z*rhs.y(); // { dg-error "not declared|no member" }
}
Vec& operator^(Vec& rhs) {
- return Vec(*this)^=rhs; // { dg-message "required" }
+ return Vec(*this)^=rhs;
}
};
Vec<double> v(3,4,12); // { dg-error "no matching|too many initializers" }
Vec<double> V(12,4,3); // { dg-error "no matching|too many initializers" }
-Vec<double> c = v^V; // { dg-message "required" }
+Vec<double> c = v^V;
diff --git a/gcc/testsuite/g++.dg/template/error35.C b/gcc/testsuite/g++.dg/template/error35.C
index d52e599315e..0ba8635507b 100644
--- a/gcc/testsuite/g++.dg/template/error35.C
+++ b/gcc/testsuite/g++.dg/template/error35.C
@@ -1,3 +1,3 @@
// PR c++/33494
-template<int> void foo(int(*f=0)()); // { dg-error "declared void|scope|erroneous-expression" }
+template<int> void foo(int(*f=0)()); // { dg-error "declared void|scope|cannot be used as a function" }
diff --git a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
index 2bfff6d9a18..b5e12d699ae 100644
--- a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
+++ b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C
@@ -3,9 +3,9 @@
template<int> struct A {};
-template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "expected primary-expression" } */
+template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "" } */
-template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "expected primary-expression" } */
+template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "" } */
int a;
More information about the Gcc-cvs
mailing list