C++ PATCH: Don't accept `asm' on fields
Mark Mitchell
mark@codesourcery.com
Sun Jan 7 17:49:00 GMT 2001
The C++ front-end crashed when confronted with:
struct S {
int i asm ("abc");
};
This construct doesn't really make sense; the C front-end doesn't
accept `asm' specifiers for fields, and there's no reason the C++
front-end should try to either.
This patch causes us to an emit a sensible error message.
Tested on i686-pc-linux-gnu.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2001-01-07 Mark Mitchell <mark@codesourcery.com>
* decl2.c (grokfield): Don't accept `asm' specifiers for
non-static data members.
Index: testsuite/g++.old-deja/g++.other/asm1.C
===================================================================
RCS file: asm1.C
diff -N asm1.C
*** /dev/null Tue May 5 13:32:27 1998
--- asm1.C Sun Jan 7 17:46:45 2001
***************
*** 0 ****
--- 1,6 ----
+ // Build don't link:
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+
+ struct S {
+ int i asm ("abc"); // ERROR - `asm' specifier not permitted
+ };
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.421
diff -c -p -r1.421 decl2.c
*** decl2.c 2001/01/07 15:17:07 1.421
--- decl2.c 2001/01/08 01:46:44
*************** grokfield (declarator, declspecs, init,
*** 1794,1808 ****
if (TREE_CODE (value) == FIELD_DECL)
{
if (asmspec)
! {
! /* This must override the asm specifier which was placed
! by grokclassfn. Lay this out fresh. */
! DECL_RTL (value) = NULL_RTX;
! DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
! }
if (DECL_INITIAL (value) == error_mark_node)
init = error_mark_node;
! cp_finish_decl (value, init, asmspec_tree, flags);
DECL_INITIAL (value) = init;
DECL_IN_AGGR_P (value) = 1;
return value;
--- 1794,1803 ----
if (TREE_CODE (value) == FIELD_DECL)
{
if (asmspec)
! cp_error ("`asm' specifiers are not permitted on non-static data members");
if (DECL_INITIAL (value) == error_mark_node)
init = error_mark_node;
! cp_finish_decl (value, init, NULL_TREE, flags);
DECL_INITIAL (value) = init;
DECL_IN_AGGR_P (value) = 1;
return value;
More information about the Gcc-patches
mailing list