clang++

creating a shared_ptr from unique_ptr

末鹿安然 提交于 2019-12-03 10:27:05
问题 In a piece of code I reviewed lately, which compiled fine with g++-4.6 , I encountered a strange try to create a std::shared_ptr from std::unique_ptr : std::unique_ptr<Foo> foo... std::make_shared<Foo>(std::move(foo)); This seems rather odd to me. This should be std::shared_ptr<Foo>(std::move(foo)); afaik, though I'm not perfectly familiar with moves (and I know std::move is only a cast, nothing get's moved). Checking with different compilers on this SSC(NUC*)E #include <memory> int main() {

Different results in Clang and GCC when casting to std::optional<T>

风格不统一 提交于 2019-12-03 09:50:57
Given the following code: #include <iostream> #include <optional> struct foo { explicit operator std::optional<int>() { return std::optional<int>( 1 ); } explicit operator int() { return 0; } }; int main() { foo my_foo; std::optional<int> my_opt( my_foo ); std::cout << "value: " << my_opt.value() << std::endl; } gcc 7.2.0 writes value: 1 . MSVC 2017 (15.3) and clang 4.0.0 however write value: 0 . Which one is correct according to the C++ standard? Since this is direct-initialization, we enumerate the constructors and just pick the best one. The relevant constructors for std::optional are :

Include search path on Mac OS X Yosemite 10.10.1

不想你离开。 提交于 2019-12-03 07:36:18
问题 I just to change the include search path order (I believe). I'd like to change the include search path. Especially, I need /usr/local/include first. But it doesn't change because of duplicate. How can I change it? I suppose there's default setting, because paths I don't specify appears. Like /usr/include/c++/4.2.1 , /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault

constexpr expression and variable lifetime, an example where g++ and clang disagree

坚强是说给别人听的谎言 提交于 2019-12-03 06:20:53
Consider the simple C++11 code: template<int N> struct Foo {}; template <int N> constexpr int size(const Foo<N>&) { return N; } template <int N> void use_size(const Foo<N>& foo) { constexpr int n = size(foo); } int main() { Foo<5> foo; constexpr int x = size(foo); // works with gcc and clang // _but_ use_size(foo); // the same statement in the use_size() // function _only_ works for gcc } I can successfuly compile it with g++ -std=c++11 foo.cpp however if I use clang++, clang++ -std=c++11 foo.cpp I get foo.cpp:15:28: error: constexpr variable 'n' must be initialized by a constant expression

clang fails replacing a statement if it contains a macro

夙愿已清 提交于 2019-12-03 05:46:20
问题 I'm using clang to try and parse (with the C++ API) some C++ files and make all the case - break pairs use a specific style. Example : **Original** switch(...) { case 1: { <code> }break; case 2: { <code> break; } } **After replacement** switch(...) { case 1: { <code> break; } case 2: { <code> break; } } What I have so far does exactly what I want if the code parts don't contain any macros. My question is: does clang treat expanded ( if I do a dump of a problematic statement it will show the

What are canonical types in Clang?

笑着哭i 提交于 2019-12-03 04:55:42
问题 I have a simple header parser based on clang and I get the typedefs from some source. struct _poire { int g; tomate rouge; }; typedef struct _poire kudamono; After parsing this I have a clang::TypedefDecl then I get the clang::QualType of the typedef with clang::TypedefDecl::getUnderlyingType() With the QualType if I use the getAsString method I can find the "struct _poire" std::string . All this is Ok. The problem is if I try to see if this type is a canonical type, with QualType:

What's the status of C++17 support in GCC?

拜拜、爱过 提交于 2019-12-03 04:46:17
问题 Clang has a nice page describing the project status w.r.t. C++1z/C++17 feature support (and C++11 and C++14, it's the same page). g++ has a page regarding C++14 features, but I couldn't find anything about C++17/C++1z. Is that being worked on but just not present on the web? For version 5.0? 回答1: As of today, gcc's C++1z language support is tracked on: https://gcc.gnu.org/projects/cxx1z.html. For the C++1z status of libstdc++, see https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

Installed clang++3.6 on Ubuntu, can't select as alternative

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 02:22:27
问题 I just installed clang++3.6 on my Ubuntu machine, but can't set it as the default c++ compiler. sudo update-alternatives --config c++ tells me that There is only one alternative in link group c++ (providing /usr/bin/c++): /usr/bin/g++ Nothing to configure. and clang++ doesn't show up in sudo update-alternatives --query c++ either (which was to be expected). But the compiler definitely works: which clang++-3.6 /usr/bin/clang++-3.6 My OS version is Ubuntu 14.04.1 LTS. What do I have to do to

What do you need to install to use Clang on windows to build c++14 for 64 bit?

旧巷老猫 提交于 2019-12-03 01:37:50
问题 UPDATE: I've written a detailed tutorial that incorporates the top two answers on this question: http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt1/ TL;DR On Windows, Given the following program: #include <iostream> int main() { int arr[] = {1, 2, 3, 4, 5}; for(auto el : arr) { std::cout << el << std::endl; } return 0; } I want to be able to do the following: clang++ hello.cpp -o hello.exe -std=c++14 And get a 64 bit executable that just works . I don't want to have to

creating a shared_ptr from unique_ptr

≡放荡痞女 提交于 2019-12-03 00:54:38
In a piece of code I reviewed lately, which compiled fine with g++-4.6 , I encountered a strange try to create a std::shared_ptr from std::unique_ptr : std::unique_ptr<Foo> foo... std::make_shared<Foo>(std::move(foo)); This seems rather odd to me. This should be std::shared_ptr<Foo>(std::move(foo)); afaik, though I'm not perfectly familiar with moves (and I know std::move is only a cast, nothing get's moved). Checking with different compilers on this SSC(NUC*)E #include <memory> int main() { std::unique_ptr<int> foo(new int); std::make_shared<int>(std::move(foo)); } Results of compilation: g++