[cfe-dev] switch over constant results in strange constructor/destructor ordering

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 16 14:13:02 PDT 2016


Wow, yes, that's a (pretty scary) wrong-code bug. Working on it...

On Fri, Sep 16, 2016 at 6:47 AM, Andrew Johnson via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello,
>
> I'm seeing an unexpected construction/destruction order in the program
> below with clang 3.9.0. Is this considered a bug? Thank you.
>
> clang asm - https://godbolt.org/g/uGlpFa
> gcc asm - https://godbolt.org/g/WDgcZP
>
> printf Output from clang (Unexpected):
> obj entered 0
> obj entered 1
> obj entered 2
> obj exited 2
> obj exited 1
> obj exited 0
>
> printf Output from gcc (Expected):
> obj entered 0
> obj exited 0
> obj entered 1
> obj exited 1
> obj entered 2
> obj exited 2
>
>
> Program:
>
> #include <stdint.h>
> #include <stdio.h>
>
> class SomeClass
> {
> uint32_t k;
> public:
> SomeClass(uint32_t x)
>         { k = x; printf("obj entered %d\n", k); }
> ~SomeClass()
>         { printf("obj exited %d\n", k); }
>
> };
>
> int main()
> {
> uint32_t ii = 0;
>
> switch(1)
> {
> default:
> {
>
> {
> SomeClass someClass(ii++);
> }
>
> {
> SomeClass someClass2(ii++);
> }
>
> {
> SomeClass someClass3(ii++);
> }
> }
> }
> }
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160916/59afb500/attachment-0001.html>


More information about the cfe-dev mailing list