From: Jason Merrill Date: Thu, 21 May 2020 14:27:11 +0000 (-0400) Subject: c++: Improve error recovery for =. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4f602147b6abbe05f862d3feda8290d4cf5c583f;p=gcc.git 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 --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 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 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 struct A {}; template struct B : A {}; // { dg-error "not supported" } template struct C : A {}; // { 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 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 v(3,4,12); // { dg-error "no matching|too many initializers" } Vec V(12,4,3); // { dg-error "no matching|too many initializers" } -Vec c = v^V; // { dg-message "required" } +Vec 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 void foo(int(*f=0)()); // { dg-error "declared void|scope|erroneous-expression" } +template 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 struct A {}; -template struct B : A {}; /* { dg-error "expected primary-expression" } */ +template struct B : A {}; /* { dg-error "" } */ -template struct C : A {}; /* { dg-error "expected primary-expression" } */ +template struct C : A {}; /* { dg-error "" } */ int a;