clang++

Issue with friend template functions clang++ / msvc++ and enable_if

这一生的挚爱 提交于 2019-12-10 10:42:09
问题 I get a compiler error in clang++. MSVC++ is happy. I believe my declarations are correct. Am I incorrect in my beliefs and I am "lucky" in MSVC? Is there a non #ifndef _MSC_VER ... public: way to make this work in both compilers? I'd like to keep the constructor private. The real code is slightly more complex. (additional template meta-programming and "perfect forwarding") The following is a distilled version for the question and to isolate the issue as much as possible. I've tried a number

Template template partial specialization only working with -std=c++1z with g++

不问归期 提交于 2019-12-10 03:45:58
问题 I have found that the following piece of code: #include <iostream> #include <vector> template <typename T> struct X : std::false_type {}; template <template <typename> class Y, typename U> struct X<Y<U>> : std::true_type {}; int main() { if (X<int>()) std::cout << "wrong\n"; if (X<std::vector<double>>()) std::cout << "correct\n"; return 0; } Only prints correct when compiled with g++-7 with -std=c++1z . Other versions of g++ , clang++ or other std flags fail to produce correct. Is this a bug

Is this unsafe usage of a braced initializer list in a range-based for loop?

旧时模样 提交于 2019-12-10 03:14:58
问题 This is very similar to a question I asked earlier today. However, the example I cited in that question was incorrect; by mistake, I was looking at the wrong source file, not the one that actually had the error I described. Anyway, here's an example of my problem: struct base { }; struct child1 : base { }; struct child2 : base { }; child1 *c1; child2 *c2; // Goal: iterate over a few derived class pointers using a range-based for loop. // initializer_lists are convenient for this, but we can't

openssl/ssl.h not found but installed with homebrew

半世苍凉 提交于 2019-12-10 02:56:15
问题 I am working on a C++ project on my Mac running El Capitan and I get this error even after installing openssl with Homebrew: g++ -Wall -g -std=c++11 -I../libSocket/src -I../libData/src -c src/fsslhandler.cpp -o obj/fsslhandler.o In file included from src/fsslhandler.cpp:1: In file included from src/fsslhandler.h:8: ../libSocket/src/sslsocket.h:6:10: fatal error: 'openssl/ssl.h' file not found #include <openssl/ssl.h> ^ 1 error generated. make: *** [obj/fsslhandler.o] Error 1 After searching

g++ and clang++ (with libc++) different behaviour with template template class specialization

梦想与她 提交于 2019-12-09 18:33:59
问题 I'm playing with c++11 and I came across a difference in behavior between g++ 4.9.2 and clang++ 3.5 (but only when it uses the libc++; when it uses the libstdc++, clang++ seems to behave as such as g++) related with a template template specialization for a template class. The following is a trivial example #include <set> template <typename X> class foo; template <template<typename, typename ...> class C, typename X> class foo<C<X>> {}; int main () { foo<std::set<int>> f; return 0; } g++

Building and using a pure llvm toolchain for c++ on linux

和自甴很熟 提交于 2019-12-09 18:29:27
问题 Assuming this is possible, could someone tell me, how I have to configure the cmake build to create a "pure" llvm toolchain on ubuntu-16.04 consisting of clang lld libc++ libc++abi libunwind (llvm) compiler-rt any other pieces that might be relevant and are "production ready" The resulting compiler should be as fast as possible (optimizations turned on, no unnecessary asserts or other checks in the compiler binary itself) be installed in a separate, local directory (lets call it <llvm_install

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

强颜欢笑 提交于 2019-12-09 05:47:45
问题 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

Clang complains “cannot override a deleted function” while no function is deleted

…衆ロ難τιáo~ 提交于 2019-12-08 19:39:34
问题 In the following simple code fragment: #include <cstddef> struct B { virtual ~B() = default; static void operator delete(void *, int); static void * operator new(size_t, int); }; struct C : B { virtual ~C() = default; }; clang 3.7 complains that "non-deleted function '~C' cannot override a deleted function": http://goo.gl/Ax6oth Neither Visual Studio nor GCC report an error in this code. Is it a clang defect or what? 回答1: static void operator delete(void *, int); No, it's static void operator

ld: symbols not found for architecture x86_64, clang: linker command failed

北慕城南 提交于 2019-12-08 17:32:23
问题 I'm trying to use homebrew to download and build packages like boost, ceres-solver, stuff like that. What happens is that I will try and compile code, without any special flags ( g++ foo.cpp -o foo -I /usr/local/... and I've tried clang++ too) and I get this error consistently: Undefined symbols for architecture x86_64: ... ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) So I looked around and the solution is to

function template overloading clang++

≡放荡痞女 提交于 2019-12-08 14:59:25
问题 g++ 4.8.1 and clang++ 3.4 give different results for next code: // simplified code from a Logger module #include <iostream> template<class T> void tf(const T*) { // clang++ std::cout << "void tf(const T*)\n"; } template<class T> void tf(T) { // g++ std::cout << "void tf(T)\n"; } int main(){ typedef std::ios_base& (*ph)(std::ios_base&); ph p = std::hex; tf(p); // or just tf(std::hex) } I can't figure out which variant is correct (C++ 03). 回答1: A pointer to function is not a pointer to an