Commit 7c67ff4a by Segher Boessenkool Committed by Segher Boessenkool

c++, asm: Do not handle any asm-qualifiers in top-level asm

Previously, "volatile" was allowed.  Changing this simplifies the code,
makes things more regular, and makes the C and C++ frontends handle
this the same way.


cp/
	* parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers
	on top-level asm.

testsuite/
	* g++.dg/asm-qual-3.C: New testcase.
	* gcc.dg/asm-qual-3.c: New testcase.

From-SVN: r267280
parent 1edf8866
2018-12-19 Segher Boessenkool <segher@kernel.crashing.org>
* parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers
on top-level asm.
2018-12-19 Segher Boessenkool <segher@kernel.crashing.org>
* parser.c (cp_parser_asm_definition) <RID_CONST, RID_RESTRICT>: Give
a more specific error message (instead of just falling through).
......
......@@ -19699,7 +19699,8 @@ cp_parser_asm_definition (cp_parser* parser)
location_t volatile_loc = UNKNOWN_LOCATION;
location_t inline_loc = UNKNOWN_LOCATION;
location_t goto_loc = UNKNOWN_LOCATION;
if (cp_parser_allow_gnu_extensions_p (parser))
if (cp_parser_allow_gnu_extensions_p (parser) && parser->in_function_body)
for (;;)
{
cp_token *token = cp_lexer_peek_token (parser->lexer);
......@@ -19718,8 +19719,6 @@ cp_parser_asm_definition (cp_parser* parser)
continue;
case RID_INLINE:
if (!parser->in_function_body)
break;
if (inline_loc)
{
error_at (loc, "duplicate asm qualifier %qT", token->u.value);
......@@ -19731,8 +19730,6 @@ cp_parser_asm_definition (cp_parser* parser)
continue;
case RID_GOTO:
if (!parser->in_function_body)
break;
if (goto_loc)
{
error_at (loc, "duplicate asm qualifier %qT", token->u.value);
2018-12-19 Segher Boessenkool <segher@kernel.crashing.org>
* g++.dg/asm-qual-3.C: New testcase.
* gcc.dg/asm-qual-3.c: New testcase.
2018-12-19 Segher Boessenkool <segher@kernel.crashing.org>
* g++.dg/asm-qual-1.C: New testcase.
* g++.dg/asm-qual-2.C: New testcase.
* gcc.dg/asm-qual-1.c: Update.
......
// Test that asm-qualifiers are not allowed on toplevel asm.
// { dg-do compile }
// { dg-options "-std=gnu++98" }
asm const (""); // { dg-error {expected '\(' before 'const'} }
asm volatile (""); // { dg-error {expected '\(' before 'volatile'} }
asm restrict (""); // { dg-error {expected '\(' before 'restrict'} }
asm inline (""); // { dg-error {expected '\(' before 'inline'} }
asm goto (""); // { dg-error {expected '\(' before 'goto'} }
// There are many other things wrong with this code, so:
// { dg-excess-errors "" }
/* Test that asm-qualifiers are not allowed on toplevel asm. */
/* { dg-do compile } */
/* { dg-options "-std=gnu99" } */
asm const (""); /* { dg-error {expected '\(' before 'const'} } */
asm volatile (""); /* { dg-error {expected '\(' before 'volatile'} } */
asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */
asm inline (""); /* { dg-error {expected '\(' before 'inline'} } */
asm goto (""); /* { dg-error {expected '\(' before 'goto'} } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment