Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #86898 > unrolled thread

creating a new local variable after a goto

Started byLynn McGuire <lynnmcguire5@gmail.com>
First post2022-10-12 21:47 -0500
Last post2022-10-13 21:55 -0500
Articles 20 on this page of 21 — 11 participants

Back to article view | Back to comp.lang.c++


Contents

  creating a new local variable after a goto Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-12 21:47 -0500
    Re: creating a new local variable after a goto Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-10-13 03:59 +0100
      Re: creating a new local variable after a goto Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-12 20:04 -0700
        Re: creating a new local variable after a goto Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-10-13 12:23 +0100
      Re: creating a new local variable after a goto Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-13 21:56 -0500
        Re: creating a new local variable after a goto "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-10-13 20:11 -0700
          Re: creating a new local variable after a goto Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-13 22:45 -0500
            Re: creating a new local variable after a goto "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-10-13 20:54 -0700
              Re: creating a new local variable after a goto "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-10-13 20:55 -0700
              Re: creating a new local variable after a goto Gawr Gura <gawrgura@mail.hololive.com> - 2022-10-14 04:41 +0000
              Re: creating a new local variable after a goto Ralf Fassel <ralfixx@gmx.de> - 2022-10-14 11:53 +0200
              Re: creating a new local variable after a goto scott@slp53.sl.home (Scott Lurndal) - 2022-10-14 13:48 +0000
                Re: creating a new local variable after a goto Richard Damon <Richard@Damon-Family.org> - 2022-10-14 13:38 -0400
                  Re: creating a new local variable after a goto scott@slp53.sl.home (Scott Lurndal) - 2022-10-14 17:53 +0000
                  Re: creating a new local variable after a goto Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-15 16:26 -0800
                    Re: creating a new local variable after a goto Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-15 17:05 -0800
            Re: creating a new local variable after a goto Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-14 01:07 -0700
              Re: creating a new local variable after a goto "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-10-14 14:32 -0700
            Re: creating a new local variable after a goto Manfred <noname@add.invalid> - 2022-10-15 01:56 +0200
    Re: creating a new local variable after a goto Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-10-12 19:59 -0700
      Re: creating a new local variable after a goto Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-13 21:55 -0500

Page 1 of 2  [1] 2  Next page →


#86898 — creating a new local variable after a goto

FromLynn McGuire <lynnmcguire5@gmail.com>
Date2022-10-12 21:47 -0500
Subjectcreating a new local variable after a goto
Message-ID<ti7u75$1n58g$1@dont-email.me>
So, I created a new local variable after a goto:

	if (crashed)
		goto L99999;
	
	std::string msg;

Visual C++ 2015 then informed me that "initialization of 'msg' is 
skipped by 'goto L99999'".

Is this a real thing, no variable with a constructor can be created 
after a goto ?

Thanks,
Lynn

[toc] | [next] | [standalone]


#86899

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2022-10-13 03:59 +0100
Message-ID<87zge0jumy.fsf@bsb.me.uk>
In reply to#86898
Lynn McGuire <lynnmcguire5@gmail.com> writes:

> So, I created a new local variable after a goto:
>
> 	if (crashed)
> 		goto L99999;
> 	
> 	std::string msg;
>
> Visual C++ 2015 then informed me that "initialization of 'msg' is
> skipped by 'goto L99999'".
>
> Is this a real thing, no variable with a constructor can be created
> after a goto ?

You can't have a goto and a matching label that might skip over an
initialisation.  The same applies to non-constructed POD types too.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#86901

FromAndrey Tarasevich <andreytarasevich@hotmail.com>
Date2022-10-12 20:04 -0700
Message-ID<ti7v7i$1n6fh$2@dont-email.me>
In reply to#86899
On 10/12/2022 7:59 PM, Ben Bacarisse wrote:
> Lynn McGuire <lynnmcguire5@gmail.com> writes:
> 
>> So, I created a new local variable after a goto:
>>
>> 	if (crashed)
>> 		goto L99999;
>> 	
>> 	std::string msg;
>>
>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>> skipped by 'goto L99999'".
>>
>> Is this a real thing, no variable with a constructor can be created
>> after a goto ?
> 
> You can't have a goto and a matching label that might skip over an
> initialisation.  The same applies to non-constructed POD types too.

It is not about "construction", it is about initialization. So called 
vacuous initialization can be bypassed. I.e. it does NOT apply to a 
"non-constructed POD" object declared without an initializer.

-- 
Best regards,
Andrey

[toc] | [prev] | [next] | [standalone]


#86922

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2022-10-13 12:23 +0100
Message-ID<87mta0j7bh.fsf@bsb.me.uk>
In reply to#86901
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> On 10/12/2022 7:59 PM, Ben Bacarisse wrote:
>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>> 
>>> So, I created a new local variable after a goto:
>>>
>>> 	if (crashed)
>>> 		goto L99999;
>>> 	
>>> 	std::string msg;
>>>
>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>> skipped by 'goto L99999'".
>>>
>>> Is this a real thing, no variable with a constructor can be created
>>> after a goto ?
>> You can't have a goto and a matching label that might skip over an
>> initialisation.  The same applies to non-constructed POD types too.
>
> It is not about "construction", it is about initialization.

Hmm... I thought I said that.  Sorry if was not clear.

> So called vacuous initialization can be bypassed. I.e. it does NOT
> apply to a "non-constructed POD" object declared without an
> initializer.

The second sentence was not intended to be read with the first.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#86940

FromLynn McGuire <lynnmcguire5@gmail.com>
Date2022-10-13 21:56 -0500
Message-ID<tiaj4l$20k7r$2@dont-email.me>
In reply to#86899
On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
> Lynn McGuire <lynnmcguire5@gmail.com> writes:
> 
>> So, I created a new local variable after a goto:
>>
>> 	if (crashed)
>> 		goto L99999;
>> 	
>> 	std::string msg;
>>
>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>> skipped by 'goto L99999'".
>>
>> Is this a real thing, no variable with a constructor can be created
>> after a goto ?
> 
> You can't have a goto and a matching label that might skip over an
> initialisation.  The same applies to non-constructed POD types too.

Thanks !

What is a POD type ?

Lynn

[toc] | [prev] | [next] | [standalone]


#86941

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2022-10-13 20:11 -0700
Message-ID<tiak1v$20os0$1@dont-email.me>
In reply to#86940
On 10/13/2022 7:56 PM, Lynn McGuire wrote:
> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>
>>> So, I created a new local variable after a goto:
>>>
>>>     if (crashed)
>>>         goto L99999;
>>>
>>>     std::string msg;
>>>
>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>> skipped by 'goto L99999'".
>>>
>>> Is this a real thing, no variable with a constructor can be created
>>> after a goto ?
>>
>> You can't have a goto and a matching label that might skip over an
>> initialisation.  The same applies to non-constructed POD types too.
> 
> Thanks !
> 
> What is a POD type ?


Plain Old Data. Iirc, there is a way to test for it:

https://en.cppreference.com/w/cpp/types/is_pod

[toc] | [prev] | [next] | [standalone]


#86942

FromLynn McGuire <lynnmcguire5@gmail.com>
Date2022-10-13 22:45 -0500
Message-ID<tiam0c$20k7r$3@dont-email.me>
In reply to#86941
On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>
>>>> So, I created a new local variable after a goto:
>>>>
>>>>     if (crashed)
>>>>         goto L99999;
>>>>
>>>>     std::string msg;
>>>>
>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>> skipped by 'goto L99999'".
>>>>
>>>> Is this a real thing, no variable with a constructor can be created
>>>> after a goto ?
>>>
>>> You can't have a goto and a matching label that might skip over an
>>> initialisation.  The same applies to non-constructed POD types too.
>>
>> Thanks !
>>
>> What is a POD type ?
> 
> 
> Plain Old Data. Iirc, there is a way to test for it:
> 
> https://en.cppreference.com/w/cpp/types/is_pod

Thanks !

And that method is deprecated already.

Lynn

[toc] | [prev] | [next] | [standalone]


#86943

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2022-10-13 20:54 -0700
Message-ID<tiamhu$20u9i$1@dont-email.me>
In reply to#86942
On 10/13/2022 8:45 PM, Lynn McGuire wrote:
> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>
>>>>> So, I created a new local variable after a goto:
>>>>>
>>>>>     if (crashed)
>>>>>         goto L99999;
>>>>>
>>>>>     std::string msg;
>>>>>
>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>> skipped by 'goto L99999'".
>>>>>
>>>>> Is this a real thing, no variable with a constructor can be created
>>>>> after a goto ?
>>>>
>>>> You can't have a goto and a matching label that might skip over an
>>>> initialisation.  The same applies to non-constructed POD types too.
>>>
>>> Thanks !
>>>
>>> What is a POD type ?
>>
>>
>> Plain Old Data. Iirc, there is a way to test for it:
>>
>> https://en.cppreference.com/w/cpp/types/is_pod
> 
> Thanks !

Cool.

> 
> And that method is deprecated already.

God damn it! Sorry Lynn. ;^o

[toc] | [prev] | [next] | [standalone]


#86944

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2022-10-13 20:55 -0700
Message-ID<tiamj6$20u9i$2@dont-email.me>
In reply to#86943
On 10/13/2022 8:54 PM, Chris M. Thomasson wrote:
> On 10/13/2022 8:45 PM, Lynn McGuire wrote:
>> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>>
>>>>>> So, I created a new local variable after a goto:
>>>>>>
>>>>>>     if (crashed)
>>>>>>         goto L99999;
>>>>>>
>>>>>>     std::string msg;
>>>>>>
>>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>>> skipped by 'goto L99999'".
>>>>>>
>>>>>> Is this a real thing, no variable with a constructor can be created
>>>>>> after a goto ?
>>>>>
>>>>> You can't have a goto and a matching label that might skip over an
>>>>> initialisation.  The same applies to non-constructed POD types too.
>>>>
>>>> Thanks !
>>>>
>>>> What is a POD type ?
>>>
>>>
>>> Plain Old Data. Iirc, there is a way to test for it:
>>>
>>> https://en.cppreference.com/w/cpp/types/is_pod
>>
>> Thanks !
> 
> Cool.
> 
>>
>> And that method is deprecated already.
> 
> God damn it! Sorry Lynn. ;^o
> 

Iirc, POD in C++ is akin to a struct in C.

[toc] | [prev] | [next] | [standalone]


#86946

FromGawr Gura <gawrgura@mail.hololive.com>
Date2022-10-14 04:41 +0000
Message-ID<tiapab$211ti$1@dont-email.me>
In reply to#86943
On Thu, 13 Oct 2022 20:54:38 -0700, Chris M. Thomasson wrote:

>>>> What is a POD type ?
>>>
>>>
>>> Plain Old Data. Iirc, there is a way to test for it:
>>>
>>> https://en.cppreference.com/w/cpp/types/is_pod
>> 
>> Thanks !
> 
> Cool.
> 
> 
>> And that method is deprecated already.
> 
> God damn it! Sorry Lynn. ;^o

You can still get this information with std::is_trivial and
std::is_standard_layout. Perhaps

template <typename T>
constexpr bool is_pod_v = std::is_trivial_v<T> && std::is_standard_layout_v<T>;

[toc] | [prev] | [next] | [standalone]


#86953

FromRalf Fassel <ralfixx@gmx.de>
Date2022-10-14 11:53 +0200
Message-ID<ygar0za91ez.fsf@akutech.de>
In reply to#86943
* "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
| On 10/13/2022 8:45 PM, Lynn McGuire wrote:
| > On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
| >> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
| >>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
| >>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
| >>> What is a POD type ?
| >>
| >>
| >> Plain Old Data. Iirc, there is a way to test for it:
| >>
| >> https://en.cppreference.com/w/cpp/types/is_pod
| >
| > Thanks !
>
| Cool.
>
| >
| > And that method is deprecated already.
>
| God damn it! Sorry Lynn. ;^o

For an alternative, see

  https://stackoverflow.com/questions/48225673/why-is-stdis-pod-deprecated-in-c20

R'

[toc] | [prev] | [next] | [standalone]


#86957

Fromscott@slp53.sl.home (Scott Lurndal)
Date2022-10-14 13:48 +0000
Message-ID<yMd2L.77214$C8y5.68572@fx07.iad>
In reply to#86943
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>On 10/13/2022 8:45 PM, Lynn McGuire wrote:
>> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>>
>>>>>> So, I created a new local variable after a goto:
>>>>>>
>>>>>>     if (crashed)
>>>>>>         goto L99999;
>>>>>>
>>>>>>     std::string msg;
>>>>>>
>>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>>> skipped by 'goto L99999'".
>>>>>>
>>>>>> Is this a real thing, no variable with a constructor can be created
>>>>>> after a goto ?
>>>>>
>>>>> You can't have a goto and a matching label that might skip over an
>>>>> initialisation.  The same applies to non-constructed POD types too.
>>>>
>>>> Thanks !
>>>>
>>>> What is a POD type ?
>>>
>>>
>>> Plain Old Data. Iirc, there is a way to test for it:
>>>
>>> https://en.cppreference.com/w/cpp/types/is_pod
>> 
>> Thanks !
>
>Cool.
>
>> 
>> And that method is deprecated already.
>
>God damn it! Sorry Lynn. ;^o
>

Deprecated doesn't mean it won't still work for the
rest of time...

[toc] | [prev] | [next] | [standalone]


#86960

FromRichard Damon <Richard@Damon-Family.org>
Date2022-10-14 13:38 -0400
Message-ID<38h2L.404269$wLZ8.129177@fx18.iad>
In reply to#86957
On 10/14/22 9:48 AM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 10/13/2022 8:45 PM, Lynn McGuire wrote:
>>> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>>>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>>>
>>>>>>> So, I created a new local variable after a goto:
>>>>>>>
>>>>>>>      if (crashed)
>>>>>>>          goto L99999;
>>>>>>>
>>>>>>>      std::string msg;
>>>>>>>
>>>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>>>> skipped by 'goto L99999'".
>>>>>>>
>>>>>>> Is this a real thing, no variable with a constructor can be created
>>>>>>> after a goto ?
>>>>>>
>>>>>> You can't have a goto and a matching label that might skip over an
>>>>>> initialisation.  The same applies to non-constructed POD types too.
>>>>>
>>>>> Thanks !
>>>>>
>>>>> What is a POD type ?
>>>>
>>>>
>>>> Plain Old Data. Iirc, there is a way to test for it:
>>>>
>>>> https://en.cppreference.com/w/cpp/types/is_pod
>>>
>>> Thanks !
>>
>> Cool.
>>
>>>
>>> And that method is deprecated already.
>>
>> God damn it! Sorry Lynn. ;^o
>>
> 
> Deprecated doesn't mean it won't still work for the
> rest of time...
> 
> 

deprecated mean it MIGHT not work under some future Standard. It is an 
advanced warning that it might be removed (but no promise that it will).

[toc] | [prev] | [next] | [standalone]


#86962

Fromscott@slp53.sl.home (Scott Lurndal)
Date2022-10-14 17:53 +0000
Message-ID<Bmh2L.65436$x5w7.26681@fx42.iad>
In reply to#86960
Richard Damon <Richard@Damon-Family.org> writes:
>On 10/14/22 9:48 AM, Scott Lurndal wrote:
>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>> On 10/13/2022 8:45 PM, Lynn McGuire wrote:
>>>> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>>>>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>>>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>>>>
>>>>>>>> So, I created a new local variable after a goto:
>>>>>>>>
>>>>>>>>      if (crashed)
>>>>>>>>          goto L99999;
>>>>>>>>
>>>>>>>>      std::string msg;
>>>>>>>>
>>>>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>>>>> skipped by 'goto L99999'".
>>>>>>>>
>>>>>>>> Is this a real thing, no variable with a constructor can be created
>>>>>>>> after a goto ?
>>>>>>>
>>>>>>> You can't have a goto and a matching label that might skip over an
>>>>>>> initialisation.  The same applies to non-constructed POD types too.
>>>>>>
>>>>>> Thanks !
>>>>>>
>>>>>> What is a POD type ?
>>>>>
>>>>>
>>>>> Plain Old Data. Iirc, there is a way to test for it:
>>>>>
>>>>> https://en.cppreference.com/w/cpp/types/is_pod
>>>>
>>>> Thanks !
>>>
>>> Cool.
>>>
>>>>
>>>> And that method is deprecated already.
>>>
>>> God damn it! Sorry Lynn. ;^o
>>>
>> 
>> Deprecated doesn't mean it won't still work for the
>> rest of time...
>> 
>> 
>
>deprecated mean it MIGHT not work under some future Standard. It is an 
>advanced warning that it might be removed (but no promise that it will).

And even if it is removed from the standard, it's likely that compilers
will continue to support it...

[toc] | [prev] | [next] | [standalone]


#87406

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2022-11-15 16:26 -0800
Message-ID<86zgcrd9sr.fsf@linuxsc.com>
In reply to#86960
Richard Damon <Richard@Damon-Family.org> writes:

> deprecated mean it MIGHT not work under some future Standard.  It is
> an advanced warning that it might be removed (but no promise that it
> will).

Deprecated does not mean the same thing as obsolescent.

Declaring a construct deprecated is a statement of intent that
the construct /will/ be removed at some indefinite time in the
future.

Declaring a construct obsolescent is meant to serve notice that
the construct should be avoided if possible because it /may/ be
removed at some future time.

[toc] | [prev] | [next] | [standalone]


#87407

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2022-11-15 17:05 -0800
Message-ID<87v8nfk8sz.fsf@nosuchdomain.example.com>
In reply to#87406
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> deprecated mean it MIGHT not work under some future Standard.  It is
>> an advanced warning that it might be removed (but no promise that it
>> will).
>
> Deprecated does not mean the same thing as obsolescent.
>
> Declaring a construct deprecated is a statement of intent that
> the construct /will/ be removed at some indefinite time in the
> future.
>
> Declaring a construct obsolescent is meant to serve notice that
> the construct should be avoided if possible because it /may/ be
> removed at some future time.

The C++ standard defines "deprecated" as "Normative for the current
edition of this International Standard, but having been identified as a
candidate for removal from future revisions.  I see no statement of
intent.  (The C standard has a similar definition, but for
"obsolescent".)

The distinction you describe would make sense, but I'd be interested in
seeing a source for it.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#86951

FromAndrey Tarasevich <andreytarasevich@hotmail.com>
Date2022-10-14 01:07 -0700
Message-ID<tib5bi$21rqs$1@dont-email.me>
In reply to#86942
On 10/13/2022 8:45 PM, Lynn McGuire wrote:
> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>
>>>>> So, I created a new local variable after a goto:
>>>>>
>>>>>     if (crashed)
>>>>>         goto L99999;
>>>>>
>>>>>     std::string msg;
>>>>>
>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>> skipped by 'goto L99999'".
>>>>>
>>>>> Is this a real thing, no variable with a constructor can be created
>>>>> after a goto ?
>>>>
>>>> You can't have a goto and a matching label that might skip over an
>>>> initialisation.  The same applies to non-constructed POD types too.
>>>
>>> Thanks !
>>>
>>> What is a POD type ?
>>
>>
>> Plain Old Data. Iirc, there is a way to test for it:
>>
>> https://en.cppreference.com/w/cpp/types/is_pod
> 
> Thanks !
> 
> And that method is deprecated already.
> 

It is deprecated because there's no such thing as "POD" in C++ anymore. 
After C++11 the language opted for a finer granularity in classifying 
its types. POD turned out to be too coarse.

-- 
Best regards,
Andrey


[toc] | [prev] | [next] | [standalone]


#86967

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2022-10-14 14:32 -0700
Message-ID<tickhb$28pbc$3@dont-email.me>
In reply to#86951
On 10/14/2022 1:07 AM, Andrey Tarasevich wrote:
> On 10/13/2022 8:45 PM, Lynn McGuire wrote:
>> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>>
>>>>>> So, I created a new local variable after a goto:
>>>>>>
>>>>>>     if (crashed)
>>>>>>         goto L99999;
>>>>>>
>>>>>>     std::string msg;
>>>>>>
>>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>>> skipped by 'goto L99999'".
>>>>>>
>>>>>> Is this a real thing, no variable with a constructor can be created
>>>>>> after a goto ?
>>>>>
>>>>> You can't have a goto and a matching label that might skip over an
>>>>> initialisation.  The same applies to non-constructed POD types too.
>>>>
>>>> Thanks !
>>>>
>>>> What is a POD type ?
>>>
>>>
>>> Plain Old Data. Iirc, there is a way to test for it:
>>>
>>> https://en.cppreference.com/w/cpp/types/is_pod
>>
>> Thanks !
>>
>> And that method is deprecated already.
>>
> 
> It is deprecated because there's no such thing as "POD" in C++ anymore. 

Well, that certainly sucks.

> After C++11 the language opted for a finer granularity in classifying 
> its types. POD turned out to be too coarse.
> 

[toc] | [prev] | [next] | [standalone]


#86972

FromManfred <noname@add.invalid>
Date2022-10-15 01:56 +0200
Message-ID<ticsvq$ib3$1@gioia.aioe.org>
In reply to#86942
On 10/14/2022 5:45 AM, Lynn McGuire wrote:
> On 10/13/2022 10:11 PM, Chris M. Thomasson wrote:
>> On 10/13/2022 7:56 PM, Lynn McGuire wrote:
>>> On 10/12/2022 9:59 PM, Ben Bacarisse wrote:
>>>> Lynn McGuire <lynnmcguire5@gmail.com> writes:
>>>>
>>>>> So, I created a new local variable after a goto:
>>>>>
>>>>>     if (crashed)
>>>>>         goto L99999;
>>>>>
>>>>>     std::string msg;
>>>>>
>>>>> Visual C++ 2015 then informed me that "initialization of 'msg' is
>>>>> skipped by 'goto L99999'".
>>>>>
>>>>> Is this a real thing, no variable with a constructor can be created
>>>>> after a goto ?
>>>>
>>>> You can't have a goto and a matching label that might skip over an
>>>> initialisation.  The same applies to non-constructed POD types too.
>>>
>>> Thanks !
>>>
>>> What is a POD type ?
>>
>>
>> Plain Old Data. Iirc, there is a way to test for it:
>>
>> https://en.cppreference.com/w/cpp/types/is_pod
> 
> Thanks !
> 
> And that method is deprecated already.
> 
> Lynn

Here's the cppreference link to the properties that have been mentioned:
https://en.cppreference.com/w/cpp/language/classes#Properties_of_classes
https://en.cppreference.com/w/cpp/language/classes#POD_class

[toc] | [prev] | [next] | [standalone]


#86900

FromAndrey Tarasevich <andreytarasevich@hotmail.com>
Date2022-10-12 19:59 -0700
Message-ID<ti7uv4$1n6fh$1@dont-email.me>
In reply to#86898
On 10/12/2022 7:47 PM, Lynn McGuire wrote:
> So, I created a new local variable after a goto:
> 
>      if (crashed)
>          goto L99999;
> 
>      std::string msg;
> 
> Visual C++ 2015 then informed me that "initialization of 'msg' is 
> skipped by 'goto L99999'".
> 
> Is this a real thing, no variable with a constructor can be created 
> after a goto ?
> 

Firstly, it is not about its being "after a goto". It is about jumping 
into the scope of the variable bypassing its initialization. So, it 
mostly depends on where 'L99999' is located, not on where 'goto' is 
located.

You can reproduce the same error "before goto":

   {
       std::string msg;
       skip:;
   }

   goto skip;

Secondly, yes, it is a real thing for variables with automatic storage 
duration. There's no such restriction for variables with static storage 
duration though. So, you can actually bypass its construction

     goto skip;
     static std::string msg;
   skip:;

At 'skip' you will see non-constructed (and therefore unusable) 'msg'.

-- 
Best regards,
Andrey


[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c++


csiph-web