clang++

Problematic clang code generation with -O0

。_饼干妹妹 提交于 2019-12-11 11:05:37
问题 The following snippet: #include <string> #include <iostream> int main() { std::string s = std::to_string(5); std::cout << s << std::endl; return 0; } Fails to link with Clang 3.6 on windows (accompanied with gcc 4.8.2 headers and libraries) when given the following options: clang++ -std=c++11 -static -O0 bug.cpp Please note that with -O2 the snippet compiles and links fine, so i suspect it may be some kind of clang bug. EDIT 1: I forgot to put the link error: F:/Programs/LLVM/bin/../lib/gcc

Inheriting default constructor fails in gcc and works in clang, which one's got the bug?

匆匆过客 提交于 2019-12-11 09:07:10
问题 Take this simple example. struct Base { // Base::Base() defined by the compiler }; struct Derived: Base { using Base::Base; // Should inherit Base::Base() Derived(int value): m_value(value) {} private: int m_value; // If Base::Base() is invoked, it's default constructed }; Derived t; As far as I understand by reading cppreference, Derived should inherit the default Base::Base() constructor and the code above should happily compile. Edit : my bad, the page I linked to tells exactly the

Print an address of function in C++, g++/clang++ vs vc++ , who is right?

帅比萌擦擦* 提交于 2019-12-11 08:54:53
问题 Consider following simple program: #include <iostream> void foo() { } int main() { std::cout<<static_cast<void*>(foo); } It compiles fine on VC++ but g++ & clang++ gives compilation errors. See live demo here ( VC++ ) See live demo here ( clang++ ) See live demo here ( g++ ) Diagnostics given by g++ & clang++ : source_file.cpp: In function ‘int main()’: source_file.cpp:4:38: error: invalid static_cast from type ‘void()’ to type ‘void*’ std::cout<<static_cast<void*>(foo); ^ So, the question is

build clang from source using specific gcc toolchain

瘦欲@ 提交于 2019-12-11 06:40:02
问题 I'm building clang from source, but using a gcc 7.2 build that doesn't live in the normal spot. I want the resulting clang++ binary to use this toolchain by default. I tried to do: $ export GCC_PREFIX=/path/to/gcc/7.2 $ mkdir -p build $ cd build $ cmake -G Ninja -DCMAKE_C_COMPILER=${GCC_PREFIX}/bin/gcc \ -DCMAKE_CXX_COMPILER=${GCC_PREFIX}/bin/g++ \ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_TARGETS_TO_BUILD=X86 .. But the resulting build just looks in /usr/include/c++/4.8.5 for standard library

Getting undefined symbol: __asan_memset when trying to use Clang address sanitizer

倖福魔咒の 提交于 2019-12-11 01:17:45
问题 I'm trying to use address sanitizer with clang to compile a C++ application but getting the following error: /Class.so: undefined symbol: __asan_memset I have added -fsanitize=address to the compiler flags /opt/llvm-3.8.0/bin/clang++ -M --gcc-toolchain=/opt/gcc-5.2.0 -fsanitize=address and I have added -fsanitize=address and -lasan to the linker flags: -fsanitize=address -lasan -shared -fuse-ld=gold-2.25 -o Class.so Class.o What else do I need to do to get this to work? 回答1: You main

SFINAE: “enable_if cannot be used to disable this declaration”

淺唱寂寞╮ 提交于 2019-12-11 00:34:37
问题 Why can I not use enable_if in the following context? I'd like to detect whether my templated object has the member function notify_exit template <typename Queue> class MyQueue { public: auto notify_exit() -> typename std::enable_if< has_member_function_notify_exit<Queue, void>::value, void >::type; Queue queue_a; }; Initialised with: MyQueue<std::queue<int>> queue_a; I keep getting (clang 6): example.cpp:33:17: error: failed requirement 'has_member_function_notify_exit<queue<int, deque<int,

How to make a parent's template method visible from a child class?

做~自己de王妃 提交于 2019-12-10 21:39:35
问题 Here is a sample code: #include <memory> class A { public: template <class T> void f(std::unique_ptr<T>, int) {} private: virtual void f(int) = 0; }; class B: public A { public: using A::f; private: virtual void f(int) override {} }; int main() { std::unique_ptr<float> a; B* b = new B; b->f(std::move(a), 1); return 0; } When I compile it with clang++, I get an error: 'f' is a private member of 'A' using A::f; ^ How to make the template method f(std::unique_ptr<T>, int) visible from class B ?

std::string initialization with a bool

谁说我不能喝 提交于 2019-12-10 20:15:27
问题 Consider the following initialization: std::string falseString = false; std::string trueString = true; With g++ 5.2.0 , compiler throws a warning for falseString , while an error for trueString . With clang++ 3.6 -std=c++11 , compiler throws error for both falseString as well as trueString . Q1) Why the different behavior with gcc even though both initialization values are of the same type ( bool )? Q2) Which compiler is correct and why? What does the standard say? EDIT: error: no viable

Decrease clang compile time with precompiled headers

流过昼夜 提交于 2019-12-10 20:08:13
问题 I am working on a database project that compiles queries (expressed in some higher level language) into c++ code. This code is compiled and executed by the database. That part works perfectly fine. Right now, I am trying to reduce the compile time for the C++ query code. I was wondering whether I can use precompiled headers to gain performance here. The query is translated into a file called Query.cpp which includes library/src/Database.hpp. The Database.hpp file includes further files like

array in std::tuple passed to std::tuple_cat in decltype error - g++ vs clang++ - which compiler is right

半世苍凉 提交于 2019-12-10 18:13:51
问题 Consider the code below: #include <tuple> int main() { std::tuple<char[2], int> t1; std::tuple<int> t2; decltype(std::tuple_cat(t1, t2)) t3; } It compiles fine with g++ (in version >= 5.2) and icc (13.0.1), but not in clang++ and older versions of g++ where it gives nasty error: array initializer must be an initializer list or string literal My hunch tells me that the code shouldn't compile and clang++ and older versions of g++ are actually right here, but want to take a second opinion. 来源: