On Wed, Mar 06, 2019 at 07:44:25PM -0500, Jason Merrill wrote: > > In addition to that, it mentions in the documentation that qualifiers are > > not allowed at toplevel asm statements; apparently our documentation at > > least from r220506 for GCC 5 says that at toplevel Basic Asm needs to be > > used and for Basic Asm lists volatile qualifier as optional and its behavior > > (that it is ignored for Basic Asm). Makes me wonder if we don't want to > > keep accepting/ignoring volatile at toplevel for both C and C++ instead of > > rejecting it (and rejecting just the other qualifiers). Thoughts on this? > > That seems reasonable. Or using warning or permerror instead of error.
This incremental patch uses warning. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-03-07 Jakub Jelinek <ja...@redhat.com> PR c++/89585 * parser.c (cp_parser_asm_definition): Just warn instead of error on volatile qualifier outside of function body. * g++.dg/asm-qual-3.C: Adjust expected diagnostics for toplevel asm volatile. --- gcc/cp/parser.c.jj 2019-03-07 09:17:41.406631683 +0100 +++ gcc/cp/parser.c 2019-03-07 10:06:49.297602880 +0100 @@ -19782,9 +19782,12 @@ cp_parser_asm_definition (cp_parser* par inform (volatile_loc, "first seen here"); } else - volatile_loc = loc; - if (!first_loc) - first_loc = loc; + { + if (!parser->in_function_body) + warning_at (loc, 0, "asm qualifier %qT ignored outside of " + "function body", token->u.value); + volatile_loc = loc; + } cp_lexer_consume_token (parser->lexer); continue; @@ -19830,10 +19833,10 @@ cp_parser_asm_definition (cp_parser* par bool inline_p = (inline_loc != UNKNOWN_LOCATION); bool goto_p = (goto_loc != UNKNOWN_LOCATION); - if (!parser->in_function_body && (volatile_p || inline_p || goto_p)) + if (!parser->in_function_body && (inline_p || goto_p)) { error_at (first_loc, "asm qualifier outside of function body"); - volatile_p = inline_p = goto_p = false; + inline_p = goto_p = false; } /* Look for the opening `('. */ --- gcc/testsuite/g++.dg/asm-qual-3.C.jj 2019-03-07 09:17:41.417631503 +0100 +++ gcc/testsuite/g++.dg/asm-qual-3.C 2019-03-07 10:11:18.160228806 +0100 @@ -3,7 +3,7 @@ // { dg-options "-std=gnu++98" } asm const (""); // { dg-error {'const' is not an asm qualifier} } -asm volatile (""); // { dg-error {asm qualifier outside of function body} } +asm volatile (""); // { dg-warning {asm qualifier 'volatile' ignored outside of function body} } asm restrict (""); // { dg-error {expected '\(' before 'restrict'} } asm inline (""); // { dg-error {asm qualifier outside of function body} } asm goto (""); // { dg-error {asm qualifier outside of function body} } Jakub