From: Jason Merrill Date: Wed, 30 May 2018 17:32:54 +0000 (-0400) Subject: Improve error recovery for structured binding in condition. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cd7fa7a74b672bb7d978807b2190feaf57afc43a;p=gcc.git Improve error recovery for structured binding in condition. * parser.c (cp_parser_check_condition_declarator): Handle cp_error_declarator. From-SVN: r260968 --- 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" } ;