Voided application of indirection operator to pointer-to-void

Voided application of indirection operator to pointer-to-void

Post by algran » Wed, 23 Jul 2003 00:06:55


Is this legal C++?

void f(void *pv) { *pv; }

Comeau and g++ both fault it. 5.3.1 says the operand of * must be T*
where T is an object type or function type - so not void. A note then
says T may be incomplete but that does not contradict the preceding,
as long as it's an incomplete object type. This is motivated by
binding references to objects of incomplete type. The note explicitly
(and redundantly) excludes void.

However, we have another source claiming the code is legal, citing 4.1
as showing an intention to allow (undereferenced) lvalues of incomplete
type and deducing that if 5.3.1 forbids this it is an oversight.

It seems to me that 4.1 only implies that lvalues of some incomplete
types may exist, and 5.3.1 indicates that those generated by the
indirection operator must have an object type. I can believe that
the committee might have intended to allow creation of void lvalues,
motivated either by orthogonality, or by compatibility with C.
But the resulting standard seems neither self-contradictory
nor obviously broken, so it is not clear there is a defect here.

I think this could still benefit from raising a core language issue -
this would be an opportunity to make the construct legal, if that was
the original intention.

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by ark » Wed, 23 Jul 2003 01:14:00

Al> Is this legal C++?

Al> void f(void *pv) { *pv; }

No.

Al> Comeau and g++ both fault it. 5.3.1 says the operand of * must be
Al> T* where T is an object type or function type - so not void. A
Al> note then says T may be incomplete but that does not contradict
Al> the preceding, as long as it's an incomplete object type. This is
Al> motivated by binding references to objects of incomplete type.
Al> The note explicitly (and redundantly) excludes void.

Sounds pretty clear, doesn't it?

Al> However, we have another source claiming the code is legal, citing
Al> 4.1 as showing an intention to allow (undereferenced) lvalues of
Al> incomplete type and deducing that if 5.3.1 forbids this it is an
Al> oversight.

I think not.

Al> It seems to me that 4.1 only implies that lvalues of some
Al> incomplete types may exist, and 5.3.1 indicates that those
Al> generated by the indirection operator must have an object type. I
Al> can believe that the committee might have intended to allow
Al> creation of void lvalues, motivated either by orthogonality, or by
Al> compatibility with C. But the resulting standard seems neither
Al> self-contradictory nor obviously broken, so it is not clear there
Al> is a defect here.

Right. Once you complete an incomplete type, you can refer to values
of that type. But void can never be completed.

Al> I think this could still benefit from raising a core language
Al> issue - this would be an opportunity to make the construct legal,
Al> if that was the original intention.

It wasn't.

Why do you want to evaluate *pv anyway if you're not going to use the
result?

--
Andrew Koenig, XXXX@XXXXX.COM

---
[ 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.yqcomputer.com/ ]

 
 
 

Voided application of indirection operator to pointer-to-void

Post by do-not-spa » Wed, 23 Jul 2003 03:33:57


<snip>

You are quite right. There are no lvalues of void type (3.10p2).


Or function type.

<snip>

I very much doubt it; I can't see that it would be meaningful to have a
void lvalue, and I don't believe C allows it either. (void rvalues do
exist in both C and C++, though.)

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by gdr » Wed, 23 Jul 2003 04:08:01


XXXX@XXXXX.COM (Ben Hutchings) writes:

| (void rvalues do
| exist in both C and C++, though.)

C does not have "rvalue". It, however, has the notion of 'lvalue'.

--
Gabriel Dos Reis, XXXX@XXXXX.COM

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by franci » Wed, 23 Jul 2003 11:01:29

In article < XXXX@XXXXX.COM >, Gabriel Dos
Reis < XXXX@XXXXX.COM > writes

Well PJ Plauger has multiple references to rvalue in the book he
co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
Reference)so I find that assertion untenable.


--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by algran » Thu, 24 Jul 2003 03:46:45


Ok, I was forgetting that in C++ function designators are still lvalues.


But that's the wrong question. The question is whether it allows
application of the indirection operator to a pointer-to-void, with
a well defined result, whether or not that result is an lvalue.
Reading 6.5.3.2 suggests this is in fact the case, and the result
is not an lvalue: note the description of the operand of the
unary & operator:
"either a function designator, the result of a [] or unary *
operator, or an lvalue that designates an object that is not
a bit-field and is not declared with the register storage-class
specifier."
Now this is curious wording if the result of unary * is always
an lvalue/FD. So it presumably is not. Reading further in 6.5.3.2
and footnote 83 suggests that the result of *pv is simply a
denotation of indirection - and that &*pv is well-defined and equal
to pv, which implies that *pv is well-defined, though of limited
usefulness. In particular, not being an lvalue, it is not subject
to the usual void-context (in C) lvalue-to-rvalue conversion.
There appears to be nothing to make it illegal.

Note that the description of unary & is more extensive than in
C89. In C89 the case of &*pv was considered in DR#12 (and ruled
illegal) and the case of (void)*pv was considered in DR#106 (and
ruled legal). DR 106 should be sufficient evidence that C++
introduced a compatibility issue for the original code example.

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by ron » Thu, 24 Jul 2003 03:47:15


The C standard doesn't ever use rvalue. Things are either lvalues or
not. C lvalues can be used in expressions directly where C++ requires
an lvalue-to-rvalue conversion.



---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by algran » Thu, 24 Jul 2003 07:57:44


The only reference to 'rvalue' in Standard C is to a footnote:

What is sometimes called "rvalue" is in this International
Standard described as the "value of an expression".

AFAICT this is true of every version of Standard C dating back
to old ANSI drafts, except it didn't say "International" then.

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by do-not-spa » Thu, 24 Jul 2003 10:30:59

In article < XXXX@XXXXX.COM >,


I know it uses the term "value of an expression", but it also notes that
this is sometimes called "rvalue". I don't think it's helpful to be
picky about slight differences of terminology when comparing C and C++.

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by franci » Fri, 25 Jul 2003 00:08:02

In article < XXXX@XXXXX.COM >, Al Grant
< XXXX@XXXXX.COM > writes


So the term is not used in the Standard but the concept is and the
footnote makes it clear that the concept used is equivalent to rvalue.

IOWs C does have rvalues, it just chose not to call them that in the
Standard.

--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by gdr » Fri, 25 Jul 2003 04:01:17


XXXX@XXXXX.COM (Al Grant) writes:


| > In article < XXXX@XXXXX.COM >, Gabriel Dos
| > Reis < XXXX@XXXXX.COM > writes
| > >C does not have "rvalue". It, however, has the notion of 'lvalue'.
| >
| > Well PJ Plauger has multiple references to rvalue in the book he
| > co-authored with Jim Brodie (ANSI and ISO Standard C Programmer's
| > Reference)so I find that assertion untenable.
|
| The only reference to 'rvalue' in Standard C is to a footnote:
|
| What is sometimes called "rvalue" is in this International
| Standard described as the "value of an expression".

Right. And the normative part of the definition of standard C never
uses, never defines what an rvalue may mean in C.

| AFAICT this is true of every version of Standard C dating back
| to old ANSI drafts, except it didn't say "International" then.

yeah.

--
Gabriel Dos Reis, XXXX@XXXXX.COM

---
[ 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.yqcomputer.com/ ]
 
 
 

Voided application of indirection operator to pointer-to-void

Post by gdr » Fri, 25 Jul 2003 11:11:53


XXXX@XXXXX.COM (Francis Glassborow) writes:

| So the term is not used in the Standard but the concept is and the
| footnote makes it clear that the concept used is equivalent to rvalue.

except that the normative text definitions of "value" and "expression"
do not really combine to make sense of the "sloppy" wording in the
non-normative text.

| IOWs C does have rvalues, it just chose not to call them that in the
| Standard.

Please have a closer look at C++ definition of rvalue and what the
non-normative text in the C standard.
The C committee chooses not to use a fuzzy word probably for good reasons.


--
Gabriel Dos Reis, XXXX@XXXXX.COM

---
[ 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.yqcomputer.com/ ]