[DTrace-devel] [PATCH] enum: support declarations with a trailing comma

Kris Van Hees kris.van.hees at oracle.com
Wed Sep 17 16:08:14 UTC 2025


On Tue, Sep 16, 2025 at 04:45:52PM -0400, Kris Van Hees wrote:
> Nice patch.  But I think it should also have an error test that verifies that
> having a missing enumerator (i.e. have ,, in the enumeration list) is indeed
> still an error.

Also, it seems to be triggering a failure on OL10.  We suspect it may be a
bison bug, but it needs further investigation (Nick will take a look).

> On Wed, Sep 03, 2025 at 03:51:04PM +0100, Alan Maguire wrote:
> > When doing python tracing, it was recently observed that #include'ing
> > a file with enum declarations with trailing commas fails; this is
> > due to the D grammar being strict about the last enumerator value
> > not having a trailing comma.  So
> > 
> > typedef enum foo {
> > 	BAR,
> > 	BAZ
> > };
> > 
> > is permitted, but
> > 
> > typdef enum foo {
> > 	BAR,
> > 	BAZ,
> > };
> > 
> > is not.  The latter pattern is used quite frequently in #include
> > files, especially where conditional compilation of some enum
> > values is done.
> > 
> > Relax this constraint and add a test to validate that D compilation
> > succeeds with the trailing comma in an enum declaration.
> > 
> > Signed-off-by: Alan Maguire <alan.maguire at oracle.com>
> > ---
> >  libdtrace/dt_grammar.y                     |  3 +-
> >  test/unittest/enum/tst.EnumTrailingComma.d | 36 ++++++++++++++++++++++
> >  2 files changed, 38 insertions(+), 1 deletion(-)
> >  create mode 100644 test/unittest/enum/tst.EnumTrailingComma.d
> > 
> > diff --git a/libdtrace/dt_grammar.y b/libdtrace/dt_grammar.y
> > index 677cd869..7984b85d 100644
> > --- a/libdtrace/dt_grammar.y
> > +++ b/libdtrace/dt_grammar.y
> > @@ -702,7 +702,8 @@ enum_definition:
> >  
> >  enumerator_list:
> >  		enumerator
> > -	|	enumerator_list DT_TOK_COMMA enumerator
> > +	|	enumerator DT_TOK_COMMA enumerator_list
> > +	|	enumerator DT_TOK_COMMA
> >  	;
> >  
> >  enumerator:	DT_TOK_IDENT { dt_decl_enumerator($1, NULL); }
> > diff --git a/test/unittest/enum/tst.EnumTrailingComma.d b/test/unittest/enum/tst.EnumTrailingComma.d
> > new file mode 100644
> > index 00000000..0414498b
> > --- /dev/null
> > +++ b/test/unittest/enum/tst.EnumTrailingComma.d
> > @@ -0,0 +1,36 @@
> > +/*
> > + * Oracle Linux DTrace.
> > + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
> > + * Licensed under the Universal Permissive License v 1.0 as shown at
> > + * http://oss.oracle.com/licenses/upl.
> > + */
> > +
> > +/*
> > + * ASSERTION:
> > + * Enumerations should support declaration with a trailing comma for
> > + * the last enumeration value.
> > + *
> > + * SECTION: Type and Constant Definitions/Enumerations
> > + *
> > + * NOTES:
> > + *
> > + */
> > +
> > +#pragma D option quiet
> > +
> > +enum colors {
> > +	RED = 1,
> > +	GREEN = 2,
> > +	BLUE = 3, 
> > +};
> > +
> > +enum shapes {
> > +	CIRCLE,
> > +	SQUARE,
> > +	TRIANGLE,
> > +};
> > +
> > +BEGIN
> > +{
> > +	exit(0);
> > +}
> > -- 
> > 2.43.5
> > 



More information about the DTrace-devel mailing list