I have the following example code:
#include <iostream> using namespace std; struct foo { foo() { cout << "foo constructed.\n"; } ~foo() { cout << "foo destroyed.\n"; } }; struct bar { bar(foo t=foo{}) { } }; int main(int argc, char **argv) { bar X[2]{}; return 0; }
When I compile it with clang++ -std=c++11 test.cc, the program produces the following output:
foo constructed. foo constructed. foo destroyed.
but I expected an additional "foo destroyed." between the two "foo constructed." lines. Why is only one foo destroyed? This happens with clang 3.5.1 as well as 3.6.0.
(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.
The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets.
Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), supporting most of its compilation flags and unofficial language extensions.
Clang Design: Like many other compilers design, Clang compiler has three phase: The front end that parses source code, checking it for errors, and builds a language-specific Abstract Syntax Tree (AST) to represent the input code. The optimizer: its goal is to do some optimization on the AST generated by the front end.
Thanks for all the people who tested it! This seems to be a bug in clang. I'd appreciate if someone reports it to llvm.org. My few bugs reports there were, let say, not really helpful, so I am not looking to repeat that experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With