Saturday, December 28, 2013

4th bullet point in iso =?UTF-8?B?wqcxMi4xIHA1IGRvZXNuJ3QgbWE=?= =?UTF-8?B?a2Ugc2Vuc2UgdG8gbWU=?=

Newsgroup: comp.lang.c++

Subject: Re: 4th bullet point in iso =?UTF-8?B?wqcxMi4xIHA1IGRvZXNuJ3QgbWE=?= =?UTF-8?B?a2Ugc2Vuc2UgdG8gbWU=?=

From: Victor Bazarov <v.bazarov@...>

Date: Sat, 28 Dec 2013 08:57:19 -0500



On 12/28/2013 7:52 AM, johnkalane@... wrote:

> Maybe I'm missing something, but IMO the 4th bullet point in iso

> ??12.1

p5 is wrong:

>

> "X is a union and all of its variant members are of const-qualified

type (or array thereof),"



First off, it's the bullet point from the enumeration of the cases when

a "defaulted default constructor is defined as deleted". In other

words, if you don't declare the c-tor or define it, it's *deleted* by

the compiler (the compiler cannot create one for you), and one of the

situations is the union with all members const.



> Take for example the following snippet which compiles in Coliru and

Ideone (http://ideone.com/QW45u7), but it shouldn't as the defaulted

default constructor for the union should be deleted according to the

bullet point alluded above.



The bullet above does not apply in this case because you *explicitly*

declare the default constructor. The bullet only applies to the

_implicitly defined_ default c-tor.



>

> union T

> {

> const int y;

> const char c;

> const float z;

> T(int j) : y(j) {}

> T() = default;

> };

>

> int main()

> {

> T t;

> }

>

> I also don't understand why does the Standard disallow this code (see note in iso ??9.5 p2)

>

> struct S

> {

> int i;

> S() : i(1) {}

> };

>

> union T

> {

> S s;

> char c;

> };

>

> int main()

> {

> T t;

> }

>

> but allows this. What's the difference?

>

> struct S

> {

> int i;

> S() : i(1) {}

> };

>

> union T

> {

> S s;

> char c;

> T() {}

> };

>

> int main()

> {

> T t;

> }



The difference is that the union T in the latter (allowed) case is NOT

*implicit*.



V

--

I do not respond to top-posted replies, please don't ask







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?160250-4th-bullet-point-in-iso-UTF-8-B-wqcxMi4xIHA1IGRvZXNuJ3QgbWE-UTF-8-B-a2Ugc2Vuc2UgdG8gbWU&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment