[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: compile lvm.c as cpp code fails at 'goto condjump'
- From: Paige DePol <lual@...>
- Date: Fri, 5 Jan 2018 17:21:00 -0600
Xavier Wang <weasley.wx@gmail.com> wrote:
> Roberto Ierusalimschy <roberto@inf.puc-rio.br>于2018年1月3日 周三下午8:22写道:
>> > for some reason, I'm compiling lua as a single cpp code (unity builds), that is, supply a `cpp` file that include all `*.c` files of lua source code
>> >
>> >
>> > everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g. lvm.c at line 1475) cause these issue
>> >
>> >
>> > ```
>> > lvm.c:1475:9: error: cannot jump from this goto statement to its label
>> > goto condjump;
>> > lvm.c:1402:17: note: jump bypasses variable initialization
>> > TValue *rb = vRB(i);
>> > ```
>>
>> This is probably a bug in your compiler. C does not have this restriction.
>> (That kind of restriction only applies to variables with a variable length
>> array.)
>
> Maybe he compiled the code in C++ mode (include codes in a cop file)? Perhaps C++ cannot do that. A check to C++ standard possibility be needed.
> --
> regards,
> Xavier Wang.
According to the specification this does appear to be the case[1]:
If transfer of control enters the scope of any automatic variables
(e.g. by jumping forward over a declaration statement), the program
is ill-formed (cannot be compiled), unless all variables whose scope
is entered have:
1) scalar types declared without initializers
2) class types with trivial default constructors and trivial destructors
declared without initializers
3) cv-qualified versions of one of the above
4) arrays of one of the above
As the declaration of 'rb' earlier in the block is also initialised this
would violate the first rule above so the compiler aborts.
My solution in a previous message should then work as it simply moves
the logic of the goto to a block without any variable declarations.
What I am confused about is why my Xcode doesn't give me an error? Even
when I specifically tell it to compile in C++ mode, and especially as it
is an error condition and not simply a warning!
~Paige
[1] http://en.cppreference.com/w/cpp/language/goto