Topic: Defect Report: an enumerator-list can be absent, but not "empty


Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Sat, 24 Mar 2007 16:04:46 CST
Raw View
On Mar 22, 12:31 pm, gennaro.pr...@yahoo.com (Gennaro Prota) wrote:
> On Thu, 22 Mar 2007 09:54:10 CST, James Kanze wrote:
> >On Mar 21, 4:07 pm, hyro...@mail.com (Hyman Rosen) wrote:
> >> Gennaro Prota wrote:
> >> >>    enum EmptyEnum {}; // OK
> >> >>    enum AbsentEnum;   // Error
> >> > That's your own vocabulary. Check the grammar, please.
>
> >> I think the reason for the confusion is that there are two
> >> sections of the standard in play.
> >> 7.2/1, describing enumeration declarations, says
> >>      enum-specifier: enum identifier-opt { enumerator-list-opt }
> >> and so an enum-specifier must indeed always have the braces.
>
> >> However, 7.1.5.3, describing elaborated type specifiers, says
> >>      elaborated-type-specifier:
> >>          enum ::opt nested-name-specifier-opt identifier
> >> so here the braces will not be present.
>
> >Note, however, that the production in 7.1.5.3 is immediately
> >followed by some constraints, in particular "If an
> >elaborated-type-specifier is the sole constituent of a
> >declaration, the declaration is ill-formed unless[...]".  None
> >of the "unless" apply here, so the second declaration above *is*
> >a syntax error.
>
> Duh. Neither me or Hyman were objecting to that. I was objecting to
>
>   The original wording is correct. An enumerator-list may be
>   empty - but not absent
>
> which is, unsurprisingly, completely wrong. (But my replies in this
> thread are pretty useless: there's no committee member so incompetent
> to be confused by such statements)

The grammar describes the potential syntactical forms of the C++
language - but it does not describe their correct semantic
interpretation. Therefore when the grammar indicates that the token
sequence for an enumerator list may or may not appear between the
curly braces in an enum definition - it necessarily leaves the meaning
of a non-appearance open to two possible semantic interpetations. And
only one of those interpretaions could be correct.

An enumator list that cannot be seen must either be absent (that is,
it does not exist or exists somewhere else) or be empty (that is, it
is present in the enum declaration after all, but simply has no
members to list). The grammar itself cannot resolve this question, but
the language of the Standard does: so the reason why a enumerator list
would not be visible in a given enum definition, is not due to any
absence (or state of non-existence) on its part - but due solely to
the fact that - as a list - it just happens to be empty.

Greg

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 21 Mar 2007 15:07:35 GMT
Raw View
Gennaro Prota wrote:
>>    enum EmptyEnum {}; // OK
>>    enum AbsentEnum;   // Error
> That's your own vocabulary. Check the grammar, please.

I think the reason for the confusion is that there are two
sections of the standard in play.
7.2/1, describing enumeration declarations, says
     enum-specifier: enum identifier-opt { enumerator-list-opt }
and so an enum-specifier must indeed always have the braces.

However, 7.1.5.3, describing elaborated type specifiers, says
     elaborated-type-specifier:
         enum ::opt nested-name-specifier-opt identifier
so here the braces will not be present.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "James Kanze" <james.kanze@gmail.com>
Date: Thu, 22 Mar 2007 09:54:10 CST
Raw View
On Mar 21, 4:07 pm, hyro...@mail.com (Hyman Rosen) wrote:
> Gennaro Prota wrote:
> >>    enum EmptyEnum {}; // OK
> >>    enum AbsentEnum;   // Error
> > That's your own vocabulary. Check the grammar, please.

> I think the reason for the confusion is that there are two
> sections of the standard in play.
> 7.2/1, describing enumeration declarations, says
>      enum-specifier: enum identifier-opt { enumerator-list-opt }
> and so an enum-specifier must indeed always have the braces.

> However, 7.1.5.3, describing elaborated type specifiers, says
>      elaborated-type-specifier:
>          enum ::opt nested-name-specifier-opt identifier
> so here the braces will not be present.

Note, however, that the production in 7.1.5.3 is immediately
followed by some constraints, in particular "If an
elaborated-type-specifier is the sole constituent of a
declaration, the declaration is ill-formed unless[...]".  None
of the "unless" apply here, so the second declaration above *is*
a syntax error.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: gennaro.prota@yahoo.com (Gennaro Prota)
Date: Thu, 22 Mar 2007 19:31:49 GMT
Raw View
On Thu, 22 Mar 2007 09:54:10 CST, James Kanze wrote:

>On Mar 21, 4:07 pm, hyro...@mail.com (Hyman Rosen) wrote:
>> Gennaro Prota wrote:
>> >>    enum EmptyEnum {}; // OK
>> >>    enum AbsentEnum;   // Error
>> > That's your own vocabulary. Check the grammar, please.
>
>> I think the reason for the confusion is that there are two
>> sections of the standard in play.
>> 7.2/1, describing enumeration declarations, says
>>      enum-specifier: enum identifier-opt { enumerator-list-opt }
>> and so an enum-specifier must indeed always have the braces.
>
>> However, 7.1.5.3, describing elaborated type specifiers, says
>>      elaborated-type-specifier:
>>          enum ::opt nested-name-specifier-opt identifier
>> so here the braces will not be present.
>
>Note, however, that the production in 7.1.5.3 is immediately
>followed by some constraints, in particular "If an
>elaborated-type-specifier is the sole constituent of a
>declaration, the declaration is ill-formed unless[...]".  None
>of the "unless" apply here, so the second declaration above *is*
>a syntax error.

Duh. Neither me or Hyman were objecting to that. I was objecting to

  The original wording is correct. An enumerator-list may be
  empty - but not absent

which is, unsurprisingly, completely wrong. (But my replies in this
thread are pretty useless: there's no committee member so incompetent
to be confused by such statements)

--
Genny

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Gennaro Prota <gennaro.prota@yahoo.com>
Date: Wed, 21 Mar 2007 08:28:02 CST
Raw View
On Fri, 16 Mar 2007 19:24:32 CST, Greg Herlihy wrote:

>On Mar 14, 10:38 am, Gennaro Prota <gennaro.pr...@yahoo.com> wrote:
>> Section [decl.enum] par. 6 states:
>>
>>   If the enumerator-list is empty, the underlying type is as if the
>>   enumeration had a single enumerator with value 0.
>>
>> But the grammar doesn't allow empty enumerator-lists; the
>> wording should probably be: "if the enumerator-list is absent"
>
>The original wording is correct. An enumerator-list may be empty - but
>not absent:
>
>    enum EmptyEnum {}; // OK
>    enum AbsentEnum;   // Error

That's your own vocabulary. Check the grammar, please.
--
Genny

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Fri, 16 Mar 2007 19:24:32 CST
Raw View
On Mar 14, 10:38 am, Gennaro Prota <gennaro.pr...@yahoo.com> wrote:
> Section [decl.enum] par. 6 states:
>
>   If the enumerator-list is empty, the underlying type is as if the
>   enumeration had a single enumerator with value 0.
>
> But the grammar doesn't allow empty enumerator-lists; the
> wording should probably be: "if the enumerator-list is absent"

The original wording is correct. An enumerator-list may be empty - but
not absent:

    enum EmptyEnum {}; // OK
    enum AbsentEnum;   // Error

Greg

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Gennaro Prota <gennaro.prota@yahoo.com>
Date: Wed, 14 Mar 2007 11:38:00 CST
Raw View
Section [decl.enum] par. 6 states:

  If the enumerator-list is empty, the underlying type is as if the
  enumeration had a single enumerator with value 0.

But the grammar doesn't allow empty enumerator-lists; the
wording should probably be: "if the enumerator-list is absent"

--
Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]