From cd7fa7a74b672bb7d978807b2190feaf57afc43a Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 30 May 2018 13:32:54 -0400 Subject: [PATCH] Improve error recovery for structured binding in condition. * parser.c (cp_parser_check_condition_declarator): Handle cp_error_declarator. From-SVN: r260968 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 7 +++++-- gcc/testsuite/g++.dg/cpp1z/decomp16.C | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 37874c02fa4..07fbafa3500 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-05-30 Jason Merrill + + * parser.c (cp_parser_check_condition_declarator): Handle + cp_error_declarator. + 2018-05-30 Jonathan Wakely * typeck.c (cxx_sizeof_or_alignof_type): Return size_one_node instead diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d17beb8f930..de090d42d8d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11594,10 +11594,13 @@ cp_parser_check_condition_declarator (cp_parser* parser, cp_declarator *declarator, location_t loc) { - if (function_declarator_p (declarator) + if (declarator == cp_error_declarator + || function_declarator_p (declarator) || declarator->kind == cdk_array) { - if (declarator->kind == cdk_array) + if (declarator == cp_error_declarator) + /* Already complained. */; + else if (declarator->kind == cdk_array) error_at (loc, "condition declares an array"); else error_at (loc, "condition declares a function"); diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp16.C b/gcc/testsuite/g++.dg/cpp1z/decomp16.C index dad69b89c08..7589c8015a5 100644 --- a/gcc/testsuite/g++.dg/cpp1z/decomp16.C +++ b/gcc/testsuite/g++.dg/cpp1z/decomp16.C @@ -8,7 +8,7 @@ void foo () { auto [ a, b ] = A (); - for (; auto [ a, b ] = A (); ) // { dg-error "expected|no match" } + for (; auto [ a, b ] = A (); ) // { dg-error "expected" } ; for (; false; auto [ a, b ] = A ()) // { dg-error "expected" } ; -- 2.30.2