public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14644] enum of value zero not converted to (null) pointer
       [not found] <bug-14644-5283@http.gcc.gnu.org/bugzilla/>
@ 2006-03-28 21:46 ` roger at eyesopen dot com
  2006-03-28 23:01 ` schwab at suse dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: roger at eyesopen dot com @ 2006-03-28 21:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from roger at eyesopen dot com  2006-03-28 21:46 -------
I believe that this may not be a g++ bug.  The wording of the standard is:
[conv.ptr] An null pointer constant is an *integral* constant expression
(_expr.const_) rvalue of integer type that evaluates to zero.
Ignoring the term "rvalue" which was the cause of the misinterpretation
of PR13867, the important aspect is the explicit use of "integral".

Both [expr.const] and [basic.fundamental] distinguish between integral and
enumeration constants.  Hence, given the definition "enum { NULL = 0 };",
I believe that "NULL" is an "enumeral constant expression", and that
"(int)NULL" is "integral constant expression".  Note that enumerators may
appear in "integral constant expressions", but are not themselves "integral
constant expressions".

See footnote 20) in section [basic.fundamental] that reiterates:
20) Therefore, enumerations (_dcl.enum_) are  not  integral;  however,
enumerations  can  be promoted to int, unsigned int, long, or unsigned
long, as specified in _conv.prom_.

Note that a standard conversion can contain at most one conversion from
the set "integral promotions" [conv.prom] and "pointer conversions"
[conv.ptr].  i.e. you can't get from enumerator to a pointer in a
single "standard conversion sequence", by my reading of the wording.

Hence in your testcase foo(NULL) is probably invalid, but foo((int)NULL)
should be fine.  Notice if that foo is overloaded, i.e. foo(int) and
foo(int*), there is no ambiguity with using foo(NULL).

Although this could perhaps be supported as a GNU extension in
cp/call.c:standard_conversion, if there are other compilers that support
this, the fact that there's a simple fix to make the source code standard
conforming, means that such a patch would unlikely be accepted.

Of course, this may be poor wording in the standard.  I notice that
Stroustrup originally used the wording "A constant expression that
evaluates to 0 ...", and again states that "a constant expression
evaluates to an integral or enumeration constant.".  So this looks like
something standardization tightened up.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/14644] enum of value zero not converted to (null) pointer
       [not found] <bug-14644-5283@http.gcc.gnu.org/bugzilla/>
  2006-03-28 21:46 ` [Bug c++/14644] enum of value zero not converted to (null) pointer roger at eyesopen dot com
@ 2006-03-28 23:01 ` schwab at suse dot de
  2006-03-28 23:09 ` schwab at suse dot de
  2006-03-31  2:28 ` mmitchel at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: schwab at suse dot de @ 2006-03-28 23:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from schwab at suse dot de  2006-03-28 23:01 -------
But [expr.const] also says:

An integral constant-expression can involve only literals (2.13), enumerators,
...

Thus enumerators are also integral constant expressions.  The distinction
between integral and enumeration is only at the type level, not as an
expression.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/14644] enum of value zero not converted to (null) pointer
       [not found] <bug-14644-5283@http.gcc.gnu.org/bugzilla/>
  2006-03-28 21:46 ` [Bug c++/14644] enum of value zero not converted to (null) pointer roger at eyesopen dot com
  2006-03-28 23:01 ` schwab at suse dot de
@ 2006-03-28 23:09 ` schwab at suse dot de
  2006-03-31  2:28 ` mmitchel at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: schwab at suse dot de @ 2006-03-28 23:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from schwab at suse dot de  2006-03-28 23:09 -------
Ignore my last comment.  The type matters, and what is needed is indeed a
constant of _integer_ type, but enumerators are not of integer type.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/14644] enum of value zero not converted to (null) pointer
       [not found] <bug-14644-5283@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2006-03-28 23:09 ` schwab at suse dot de
@ 2006-03-31  2:28 ` mmitchel at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-03-31  2:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2006-03-31 02:28 -------
As Roger says, this not a bug.  Roger's analysis is spot on.  (For reference,
EDG also rejects this program.)


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/14644] enum of value zero not converted to (null) pointer
  2004-03-19  4:17 [Bug c++/14644] New: " llewins at raytheon dot com
  2004-03-19  4:30 ` [Bug c++/14644] " pinskia at gcc dot gnu dot org
@ 2004-04-27 19:26 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-27 19:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-27 19:17 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-04-27 19:17:22
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/14644] enum of value zero not converted to (null) pointer
  2004-03-19  4:17 [Bug c++/14644] New: " llewins at raytheon dot com
@ 2004-03-19  4:30 ` pinskia at gcc dot gnu dot org
  2004-04-27 19:26 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-19  4:30 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |3.5.0 2.95.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14644


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-03-31  2:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-14644-5283@http.gcc.gnu.org/bugzilla/>
2006-03-28 21:46 ` [Bug c++/14644] enum of value zero not converted to (null) pointer roger at eyesopen dot com
2006-03-28 23:01 ` schwab at suse dot de
2006-03-28 23:09 ` schwab at suse dot de
2006-03-31  2:28 ` mmitchel at gcc dot gnu dot org
2004-03-19  4:17 [Bug c++/14644] New: " llewins at raytheon dot com
2004-03-19  4:30 ` [Bug c++/14644] " pinskia at gcc dot gnu dot org
2004-04-27 19:26 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).