Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating a new local variable after a goto

43 views
Skip to first unread message

Lynn McGuire

unread,
Oct 12, 2022, 10:47:22 PM10/12/22
to
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

Ben Bacarisse

unread,
Oct 12, 2022, 11:00:06 PM10/12/22
to
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.

Andrey Tarasevich

unread,
Oct 12, 2022, 11:00:06 PM10/12/22
to
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



Andrey Tarasevich

unread,
Oct 12, 2022, 11:04:36 PM10/12/22
to
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


Ben Bacarisse

unread,
Oct 13, 2022, 7:23:46 AM10/13/22
to
Andrey Tarasevich <andreyta...@hotmail.com> writes:

> On 10/12/2022 7:59 PM, Ben Bacarisse wrote:
>> Lynn McGuire <lynnmc...@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.

Lynn McGuire

unread,
Oct 13, 2022, 10:56:11 PM10/13/22
to
Thanks !

Lynn


Lynn McGuire

unread,
Oct 13, 2022, 10:56:38 PM10/13/22
to
Thanks !

What is a POD type ?

Lynn

Chris M. Thomasson

unread,
Oct 13, 2022, 11:12:17 PM10/13/22
to
Plain Old Data. Iirc, there is a way to test for it:

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

Lynn McGuire

unread,
Oct 13, 2022, 11:45:34 PM10/13/22
to
Thanks !

And that method is deprecated already.

Lynn

Chris M. Thomasson

unread,
Oct 13, 2022, 11:54:55 PM10/13/22
to
Cool.

>
> And that method is deprecated already.

God damn it! Sorry Lynn. ;^o

Chris M. Thomasson

unread,
Oct 13, 2022, 11:55:35 PM10/13/22
to
Iirc, POD in C++ is akin to a struct in C.

Gawr Gura

unread,
Oct 14, 2022, 12:42:06 AM10/14/22
to
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>;

Andrey Tarasevich

unread,
Oct 14, 2022, 4:07:31 AM10/14/22
to
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



Ralf Fassel

unread,
Oct 14, 2022, 5:53:42 AM10/14/22
to

Scott Lurndal

unread,
Oct 14, 2022, 9:48:30 AM10/14/22
to
Deprecated doesn't mean it won't still work for the
rest of time...


Richard Damon

unread,
Oct 14, 2022, 1:38:24 PM10/14/22
to
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).

Scott Lurndal

unread,
Oct 14, 2022, 1:53:55 PM10/14/22
to
And even if it is removed from the standard, it's likely that compilers
will continue to support it...

Chris M. Thomasson

unread,
Oct 14, 2022, 5:32:44 PM10/14/22
to
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 <lynnmc...@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.

Manfred

unread,
Oct 14, 2022, 7:57:01 PM10/14/22
to

Tim Rentsch

unread,
Nov 15, 2022, 7:26:27 PM11/15/22
to
Richard Damon <Ric...@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.

Keith Thompson

unread,
Nov 15, 2022, 8:06:05 PM11/15/22
to
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.T...@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
0 new messages