[cfe-dev] switch over constant results in strange constructor/destructor ordering
Andrew Johnson via cfe-dev
cfe-dev at lists.llvm.org
Fri Sep 16 06:47:51 PDT 2016
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++);
}
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160916/539adfeb/attachment.html>
More information about the cfe-dev
mailing list