Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
type traits if void type
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mateusz Loskot  
View profile  
 More options May 27 2009, 12:55 pm
Newsgroups: comp.std.c++
From: "Mateusz Loskot" <mate...@loskot.net>
Date: Wed, 27 May 2009 10:55:04 CST
Local: Wed, May 27 2009 12:55 pm
Subject: type traits if void type
Hi,

May I kindly ask for interpretation of correct/standard behavior of type
traits applied to void type?

What is expected output of the test below according to n2857?

#include <iostream>
#include <type_traits>
int main()
{
     std::cout << std::is_pod<void>::value << std::endl;
     std::cout << std::has_trivial_destructor<void>::value << std::endl;

}

Here is what I get:

1) GCC 4.3.3

0
0

2) Visual C++ 9.0 (cl 15.00.30729.01)

1
1

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
pl.comp.lang.c FAQ: http://pl.cpp.wikia.com/wiki/FAQ
C++ FAQ: http://parashift.com/c++-faq-lite

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wasti.r...@gmx.net  
View profile  
 More options May 27 2009, 11:05 pm
Newsgroups: comp.std.c++
From: wasti.r...@gmx.net
Date: Wed, 27 May 2009 21:05:15 CST
Local: Wed, May 27 2009 11:05 pm
Subject: Re: type traits if void type
On May 27, 6:55 pm, "Mateusz Loskot" <mate...@loskot.net> wrote:

VC++ is wrong. void is not a POD type.

"Arithmetic types, enumeration types, pointer types, pointer to member
types, and std::nullptr_t, and cv-qualified versions of these types are
collectively called scalar types. Scalar types, POD classes, arrays of
such types and cv-qualified versions of these types are collectively
called POD types."

Since void is not a scalar type, nor a class, it cannot be a POD.

Sebastian

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
daniel.krueg...@googlemail.com  
View profile  
 More options May 27 2009, 11:23 pm
Newsgroups: comp.std.c++
From: daniel.krueg...@googlemail.com
Date: Wed, 27 May 2009 21:23:00 CST
Subject: Re: type traits if void type
On 27 Mai, 18:55, "Mateusz Loskot" <mate...@loskot.net> wrote:

The expected output is equivalent to that of gcc.

This can be easily read from the WP:

1) std::is_pod<void>: As of Table 33 the precondition is satisfied,
because cv-void is a feasible argument. The test conditions refers
to 3.9 [basic.types], where we find in p. 10:

"Arithmetic types (3.9.1), enumeration types, pointer types,
pointer to member types (3.9.2), and std::nullptr_t, and cv-
qualified versions of these types (3.9.3) are collectively called
scalar types. Scalar types, POD classes (Clause 9), arrays of
such types and cv-qualified versions of these types (3.9.3) are
collectively called POD types [..]"

and in 3.9.1 [basic.fundamental]/9:

"[..] Integral and floating types are collectively called arithmetic
types.[..]"

Therefore the test condition isn't satisfied, the result should
be false.

2)  std::has_trivial_destructor<void>: The same Table 33
tells us that the test pre-conditions are satisfied, because
cv-void is a feasible argument.

Regarding the test result we end up in checking that
"T is a trivial type (3.9)" is the only relevant choice, but
according to 3.9 [basic.types]/10

"[..] Scalar types, trivial class types (Clause 9), arrays of such
types and cv-qualified versions of these types (3.9.3) are
collectively called trivial types."

we have a negative result again, because void is no scalar
type as shown above.

HTH & Greetings from Bremen,

Daniel Kr gler

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Dennett  
View profile  
 More options May 28 2009, 6:26 pm
Newsgroups: comp.std.c++
From: James Dennett <james.denn...@gmail.com>
Date: Thu, 28 May 2009 16:26:08 CST
Local: Thurs, May 28 2009 6:26 pm
Subject: Re: type traits if void type
On May 27, 9:55 am, "Mateusz Loskot" <mate...@loskot.net> wrote:

> Hi,

> May I kindly ask for interpretation of correct/standard behavior of type
> traits applied to void type?

> What is expected output of the test below according to n2857?

> #include <iostream>
> #include <type_traits>
> int main()
> {
>      std::cout << std::is_pod<void>::value << std::endl;

void is not a POD type, so std::is_pod<void>::value must be false.

"Arithmetic types (3.9.1), enumeration types, pointer types, pointer
to member types (3.9.2), and std::nullptr_t, and cv-qualified versions
of these types (3.9.3) are collectively called scalar types. Scalar
types, POD classes (Clause 9), arrays of such types and cv-qualified
versions of these types (3.9.3) are collectively called POD types."

>      std::cout << std::has_trivial_destructor<void>::value << std::endl;

has_trivial_destructor<T>::value is defined by "T is a trivial type
(3.9) or a reference type or a class type with a trivial destructor
(12.4) or an array of such a class type."

void is not a trivial type ("Scalar types, trivial class types (Clause
9), arrays of such types and cv-qualified versions of these types
(3.9.3) are collectively called trivial types."), so
has_trivial_destructor<void>::value is also false.

> Here is what I get:

> 1) GCC 4.3.3

> 0
> 0

I believe gcc has this right...

> 2) Visual C++ 9.0 (cl 15.00.30729.01)

> 1
> 1

VC++9 disagrees with me.

-- James

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mateusz Loskot  
View profile  
 More options May 29 2009, 10:27 am
Newsgroups: comp.std.c++
From: "Mateusz Loskot" <mate...@loskot.net>
Date: Fri, 29 May 2009 08:27:56 CST
Local: Fri, May 29 2009 10:27 am
Subject: Re: type traits if void type
<daniel.krueg...@googlemail.com> wrote in message

news:aaa536fd-909a-4607-aad3-e456409b028d@o18g2000yqi.googlegroups.com...

Daniel,

Now, everything is clear. Thanks to you too!

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
pl.comp.lang.c FAQ: http://pl.cpp.wikia.com/wiki/FAQ
C++ FAQ: http://parashift.com/c++-faq-lite

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mateusz Loskot  
View profile  
 More options May 29 2009, 10:27 am
Newsgroups: comp.std.c++
From: "Mateusz Loskot" <mate...@loskot.net>
Date: Fri, 29 May 2009 08:27:28 CST
Local: Fri, May 29 2009 10:27 am
Subject: Re: type traits if void type
<wasti.r...@gmx.net> wrote in message

news:a41628a4-e7d4-4546-aa72-5d40abc5e963@h28g2000yqd.googlegroups.com...

Sebastian,

Understood. Thank you very much for confirmation.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
pl.comp.lang.c FAQ: http://pl.cpp.wikia.com/wiki/FAQ
C++ FAQ: http://parashift.com/c++-faq-lite

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Becker  
View profile  
 More options May 29 2009, 4:25 pm
Newsgroups: comp.std.c++
From: Pete Becker <p...@versatilecoding.com>
Date: Fri, 29 May 2009 14:25:08 CST
Local: Fri, May 29 2009 4:25 pm
Subject: Re: type traits if void type

[tr.meta.req]/8 in TR1 requires is_pod<void>::value to be 1. n2857 is
not a standard, and implementations of previous standards are not
wrong for not doing what isn't yet required of them.

--
 Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Dennett  
View profile  
 More options May 29 2009, 5:47 pm
Newsgroups: comp.std.c++
From: James Dennett <james.denn...@gmail.com>
Date: Fri, 29 May 2009 15:47:04 CST
Local: Fri, May 29 2009 5:47 pm
Subject: Re: type traits if void type
On May 29, 1:25 pm, Pete Becker <p...@versatilecoding.com> wrote:

TR1 does not define std::is_pod, only std::tr1::is_pod.  The most
authoritative definitions of std::is_pod (and
std::has_trivial_destructor etc.) currently available are in the C++0x
drafts edited by your good self.

That said, I'd like to see real-world examples of code that depend on
the particular value of either of these traits for T=void.  I can't
imagine how you'd use the knowledge that void is/is not POD, or does/
does not have a trivial destructor, when there are no objects of type
void.

-- James

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Becker  
View profile  
 More options May 30 2009, 2:04 pm
Newsgroups: comp.std.c++
From: Pete Becker <p...@versatilecoding.com>
Date: Sat, 30 May 2009 12:04:06 CST
Local: Sat, May 30 2009 2:04 pm
Subject: Re: type traits if void type

Under the current standard, using the name std::is_pod requires a
diagnostic. So if you want to be literal, both compilers are "wrong".
Nevertheless, neither is really "wrong", they just implement different
non-standard versions of is_pod.

--
    Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rhialto  
View profile  
 More options May 30 2009, 2:04 pm
Newsgroups: comp.std.c++
From: Rhialto <rhia...@falu.nl>
Date: Sat, 30 May 2009 12:04:45 CST
Local: Sat, May 30 2009 2:04 pm
Subject: Re: type traits if void type

James Dennett wrote:
> That said, I'd like to see real-world examples of code that depend on
> the particular value of either of these traits for T=void.  I can't
> imagine how you'd use the knowledge that void is/is not POD, or does/
> does not have a trivial destructor, when there are no objects of type
> void.

Once I dabbled in a C compiler which I extended to allow objects of type
void (and arrays with 0 elements, which was also officially forbidden).
You could write for instance

void func()
{
        void a, b;
        if (conditon)
                a = func();
        else
                a = b;
        return a;

}

all of which obviously without any "real assignment" activity. This
isn't very "useful" but I thought it was good for symmetry.

In this compiler, if it were a C++ compiler, void would be a POD type
and have a trivial destructor.

> -- James

-Olaf
--
___ Olaf 'Rhialto' Seibert    -- You author it, and I'll reader it.
\X/ rhialto/at/xs4all.nl      -- Cetero censeo "authored" delendum esse.

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Smith  
View profile  
 More options Jun 1 2009, 4:33 am
Newsgroups: comp.std.c++
From: "Joe Smith" <unknown_kev_...@hotmail.com>
Date: Mon, 1 Jun 2009 02:33:05 CST
Local: Mon, Jun 1 2009 4:33 am
Subject: Re: type traits if void type

"Rhialto" <rhia...@falu.nl> wrote in message

news:4a20fb36$0$194$e4fe514c@news.xs4all.nl...

I agree that conceptually void is more of a pod type, than a non-pod type,
and logically the constructor is not non-trivial, so it would seem
reasonable for it to be considered trvially destructable.

So to me I actually slightly perfer the output of VC++9. Yes, it does not
match the current working paper, but I feel the working paper could
reasonably be changed there, and nobody would complain.

Of course your toy language above seems to have left out some of ther harder
decisions. Should the built-in types be implicitly convertible to void (or
should explicit casts to void be required)? Should a call to a function of
no paramaters be allowerd to have arguments of type void? Should a function
be allowed to have formal parameters of type void? Then if we look at a
similar C++ extention, we would need to consider how void arguments would
interact with overloading, and template deduction.

Of course, that might actually make "void()" (i.e. explictly creating an
rvalue of type void) actually useful in some circumstances (outside of
templates, which is the only place it might currently be useful.)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rhialto  
View profile  
 More options Jun 2 2009, 7:25 pm
Newsgroups: comp.std.c++
From: Rhialto <rhia...@falu.nl>
Date: Tue, 2 Jun 2009 17:25:58 CST
Local: Tues, Jun 2 2009 7:25 pm
Subject: Re: type traits if void type

Joe Smith wrote:
> Of course your toy language above seems to have left out some of the harder
> decisions.

I don't really recall if I tried to resolve those decisions in some way;
it was about 20 years ago and one of those night-time programming
projects. But I think I did it with the most minimal changes possible by
pretending in most places that variables of void type were similar to
other variables. So this would likely result in the following:

> Should the built-in types be implicitly convertible to void (or
> should explicit casts to void be required)?

Since both "func();" and "1;" are convertible to void without cast
(although some compilers give a warning on at least the second case),
"void a = func_returning_nonvoid();" would probably work the same.

> Should a call to a function of
> no paramaters be allowerd to have arguments of type void?

No. Although the declaration "int func(void);" (to indicate it has no
parameters) would confuse matters. I'm not sure what I did there. This C
syntax is weird anyway, and only needed for backwards compatibility with
pre-prototype C. C++ would not have this problem.

> Should a function
> be allowed to have formal parameters of type void?

Yes. And it would make different function signatures from "int func(int
a)" and "int func2(int a, void b);". Calling func2 would be a bit weird
if you have no variable of type void at hand, since you'd need a
denotation for a void object; something like "x = func2(1, (void)0);".
Somewhat weird. (The denotation "void()" you used looks better)

> Then if we look at a
> similar C++ extention, we would need to consider how void arguments would
> interact with overloading, and template deduction.

Expanding on the above, I'd say (if such a proposal were ever made) that
   presence of void arguments would matter (i.e., they are not "optimized
away" before matching types for overloading and template deduction).

I am in fact just realising that a current wart in the overloading
system could have been done (slightly) more elegantly with a void
parameter: the difference between a pre- and post-inc/decrement operator
is currently made with a dummy "int" parameter. Using "void" there would
have been slightly neater.

-Olaf
--
___ Olaf 'Rhialto' Seibert    -- You author it, and I'll reader it.
\X/ rhialto/at/xs4all.nl      -- Cetero censeo "authored" delendum esse.

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mateusz Loskot  
View profile  
 More options Jun 2 2009, 7:23 pm
Newsgroups: comp.std.c++
From: "Mateusz Loskot" <mate...@loskot.net>
Date: Tue, 2 Jun 2009 17:23:19 CST
Local: Tues, Jun 2 2009 7:23 pm
Subject: Re: type traits if void type
"James Dennett" <james.denn...@gmail.com> wrote in message

news:29d54583-85e6-4623-a74a-410d14875ce3@r34g2000vba.googlegroups.com...

The is_pod<T> predicate is used in std library in Visual C++ 9.0 to implemet
other predicates, for instance  has_trivial_destructor:

  // TEMPLATE CLASS has_trivial_destructor
template<class _Ty>
struct has_trivial_destructor
     : _Cat_base<is_pod<_Ty>::value || __has_trivial_destructor(_Ty)>
  { // determine whether _Ty has a trivial destructor
  };

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
pl.comp.lang.c FAQ: http://pl.cpp.wikia.com/wiki/FAQ
C++ FAQ: http://parashift.com/c++-faq-lite

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mateusz Loskot  
View profile  
 More options Jul 27 2009, 7:54 pm
Newsgroups: comp.std.c++
From: "Mateusz Loskot" <mate...@loskot.net>
Date: Mon, 27 Jul 2009 17:54:35 CST
Local: Mon, Jul 27 2009 7:54 pm
Subject: Re: type traits if void type
"Mateusz Loskot" <mate...@loskot.net> wrote in message

news:gvj6f4$4og$1@inews.gazeta.pl...

Just to complete the discussion, here is a short feedback from Microsoft:

ID:458570 - has_trivial_destructor applied to void returns true

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx...

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
pl.comp.lang.c FAQ: http://pl.cpp.wikia.com/wiki/FAQ
C++ FAQ: http://parashift.com/c++-faq-lite

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »