clang++

Access maximum template depth at compile?

拈花ヽ惹草 提交于 2019-12-24 01:49:09
问题 In a certain compilation I need to play around with the option -ftemplate-depth=N that specifies the maximum template recursion. Is it possible to access the value of the maximum template depth from the program? I am interested in gcc or clang . $ c++ -ftemplate-depth=128 main.cpp #include<iostream> int main(){ std::cout << MAX_TEMPLATE_RECURSION << std::endl; // hypothetical name } 来源: https://stackoverflow.com/questions/36227436/access-maximum-template-depth-at-compile

clang++ auto return type error for specialization of templated method in templated class?

橙三吉。 提交于 2019-12-24 01:13:01
问题 Trying to understand another question, I've simplified the example obtaining the following code. template <bool> struct foo { template <typename T> auto bar (int i) { return i; } }; template <> template <typename T> auto foo<true>::bar (int i) { return i; } int main() { return 0; } g++ 4.9.2 compile it without problem; clang++ 3.5 give the following error tmp_003-14,gcc,clang.cpp:12:20: error: out-of-line definition of 'bar' does not match any declaration in 'foo<true>' auto foo<true>::bar

Clang: error: invalid use of non-static data member

寵の児 提交于 2019-12-23 19:58:25
问题 Is this gcc being overly nice and doing what the dev thinks it will do or is clang being overly fussy about something. Am I missing some subtle rule in the standard where clang is actually correct in complaining about this Or should I use the second bit of code which is basically the how offsetof works [adrian@localhost ~]$ g++ -Wall -pedantic -ansi a.cc [adrian@localhost ~]$ a.out 50 [adrian@localhost ~]$ cat a.cc #include <iostream> struct Foo { char name[50]; }; int main(int argc, char

clang appears not to be linking to a library

江枫思渺然 提交于 2019-12-23 10:59:29
问题 I boiled down the problem to the following example: int main() { try { throw false; } catch (bool x) { if (x) { return 0; } else { return 1; } } } generates the following errors on Coliru: /tmp/main-c8b47a.o: In function `main': main.cpp:(.text+0xf): undefined reference to `typeinfo for bool' /tmp/main-c8b47a.o: In function `GCC_except_table0': main.cpp:(.gcc_except_table+0x30): undefined reference to `typeinfo for bool' clang: error: linker command failed with exit code 1 (use -v to see

clang appears not to be linking to a library

六眼飞鱼酱① 提交于 2019-12-23 10:59:20
问题 I boiled down the problem to the following example: int main() { try { throw false; } catch (bool x) { if (x) { return 0; } else { return 1; } } } generates the following errors on Coliru: /tmp/main-c8b47a.o: In function `main': main.cpp:(.text+0xf): undefined reference to `typeinfo for bool' /tmp/main-c8b47a.o: In function `GCC_except_table0': main.cpp:(.gcc_except_table+0x30): undefined reference to `typeinfo for bool' clang: error: linker command failed with exit code 1 (use -v to see

Non-type template argument is not a constant expression

假如想象 提交于 2019-12-23 10:15:08
问题 I have the following code: #include <cstdlib> #include <cstdio> #include <atomic> enum ATYPE { Undefined = 0, typeA, typeB, typeC }; template<ATYPE TYPE = Undefined> struct Object { Object() { counter++; } static std::atomic<int> counter; }; template<ATYPE TYPE> std::atomic<int> Object<TYPE>::counter(1); template<ATYPE TYPE> void test() { printf("in test\n"); Object<TYPE> o; } int main(int argc, char **argv) { test<typeA>(); printf("%d\n", Object<typeA>::counter.load()); Object<typeA>:

Wrong overload called when constructing from initializer_list inside parentheses

北战南征 提交于 2019-12-23 09:39:30
问题 I always thought that when I use initializer list C++ syntax like: something({ ... }); it's always clear to the compiler that I want to call the overload taking an std::initializer_list , but it seems this is not so clear for MSVC 2015. I tested this simple code: #include <cstdio> #include <initializer_list> namespace testing { template<typename T> struct Test { Test() { printf("Test::Test()\n"); } explicit Test(size_t count) { printf("Test::Test(int)\n"); } Test(std::initializer_list<T> init

g++ and clang++ different behaviour with SFINAE and SFINAE failure

余生长醉 提交于 2019-12-23 09:28:07
问题 A couple of questions for C++11 experts. I'm fighting with SFINAE and I came across a strange case in which g++ (4.9.2), and clang++ (3.5.0) behave differently. I have prepared the following sample code. I'm sorry but I'm unable to do it significantly more concise. #include <string> #include <iostream> #include <typeinfo> #include <type_traits> template <typename X> class foo { private: template <typename R> using enableIfIsInt = typename std::enable_if<std::is_same<X, int>::value, R>::type;

AddressSanitizer / LeakSanitizer Error with -lsupc++ and -stdlib=libc++ on a never called virtual function that writes to a stream

徘徊边缘 提交于 2019-12-22 17:57:22
问题 The following code throws an AddressSanitizer Error when compiled on Debian Jessie with clang 3.5. It appears to be related to the combination of linked libraries, but i have not been able to find something similar on the internet. Reproduction of the Error Invocation: clang++ -stdlib=libc++ -lc++abi -fsanitize=address,vptr sample.cpp -lsupc++ -o sample //sample.cpp #include <iostream> class Foo { virtual void bar() { std::cerr << std::endl; } public: virtual ~Foo() { } }; int main() { Foo

Vectorize a function in clang

情到浓时终转凉″ 提交于 2019-12-22 03:40:54
问题 I am trying to vectorize the following function with clang according to this clang reference. It takes a vector of byte array and applies a mask according to this RFC. static void apply_mask(vector<uint8_t> &payload, uint8_t (&masking_key)[4]) { #pragma clang loop vectorize(enable) interleave(enable) for (size_t i = 0; i < payload.size(); i++) { payload[i] = payload[i] ^ masking_key[i % 4]; } } The following flags are passed to clang: -O3 -Rpass=loop-vectorize -Rpass-analysis=loop-vectorize