Created
November 15, 2016 16:20
-
-
Save icebreaker/14ca27556be954124ea04d4e34eff043 to your computer and use it in GitHub Desktop.
weird clang++ / g++ behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ clang++ -O0 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 1 | |
$ clang++ -O1 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 1 | |
$ clang++ -O2 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 2 | |
$ clang++ -O3 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 2 | |
$ g++ -O0 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 1 | |
$ g++ -O1 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 2 | |
$ g++ -O2 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 2 | |
$ g++ -O3 test1.cpp test2.cpp -o simple; ./simple | |
destructor 1 | |
destructor 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "test2.hpp" | |
struct data | |
{ | |
~data() | |
{ | |
printf("destructor 1\n"); | |
} | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
data *a = new data; | |
delete a; | |
test_data(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct data | |
{ | |
~data() | |
{ | |
printf("destructor 2\n"); | |
} | |
}; | |
void test_data(void) | |
{ | |
data *a = new data; | |
delete a; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void test_data(void); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment