clang++

Error when casting temporary object to non-const reference

南楼画角 提交于 2020-01-13 09:45:12
问题 Here is a reproducible example taken from question about using temporary stringstream object: #include <sstream> #include <string> #include <iostream> using namespace std; std::string transform(std::string); int main() { int i{}; cout << transform( static_cast<stringstream &>(stringstream() << i).str() ); } When trying to compile with clang version 9.0.0 under MacOS High Sierra I got following error: $ clang++ -std=c++11 x.cc -c x.cc:12:24: error: non-const lvalue reference to type 'basic

XCode 9: “clang: error: cannot specify -o when generating multiple output files”

本小妞迷上赌 提交于 2020-01-12 08:01:12
问题 I've just updated xcode to version 9 and I've started getting the following error message when compiling: clang: error: cannot specify -o when generating multiple output files The issue seems to be linked to compiling with the "Optimization Level" parameter set to "None" (i.e. -O0). If I set this higher the error goes away, BUT when I increase the optimization the debugging tools do not work appropriately (for example variable tracking). I've looked at other questions that list this error,

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

拟墨画扇 提交于 2020-01-12 06:26:10
问题 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? 回答1: Since this is direct-initialization, we

static library convert to a shared lib symbols are hidden?

余生颓废 提交于 2020-01-06 04:32:11
问题 I am trying to link v8's static library to a shared library using the following cmake command add_library(v8jni SHARED ${THIRDPARTY_LIB_PATH}/shared/v8jni.cpp) target_link_libraries(v8jni log -Wl,--whole-archive v8_inspector v8_base v8_snapshot v8_libplatform v8_libsampler v8_libbase -Wl,--no-whole-archive) libv8jni.so is generated successfully. But it's useless because all the v8 function are marked as local. nm -C libv8_base.a | grep v8::HandleScope 00000000 T v8::HandleScope::Initialize(v8

What compiler option/library do I need to use detect_or_t type trait?

我的梦境 提交于 2020-01-05 14:09:15
问题 I am trying to use std::experimental::detect_or_t from <experimental/type_traits> . What compiler, option, version or library do I need to compile the following example from http://en.cppreference.com/w/cpp/experimental/is_detected ? #include <experimental/type_traits> #include <cstddef> template<class T> using diff_t = typename T::difference_type; template <class Ptr> using difference_type = std::experimental::detected_or_t<std::ptrdiff_t, diff_t, Ptr>; struct Meow { using difference_type =

Can't link libFuzzer.a using clang with libc++

喜欢而已 提交于 2020-01-05 04:03:12
问题 I'm trying to link together: libFuzzer.a, compiled with clang++-5.0 and -std=c++11 my fuzz driver, compiled with clang++-5.0 and -std=c++11 -stdlib=libc++ libcurl, compiled with clang-5.0 Specifically, this linker command is being executed: /bin/bash ../../libtool --silent --tag=CXX --mode=link clang++-5.0 -I../../include -I../../lib -I../../lib -I../../tests/fuzz -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp -std=c++11 -stdlib=libc++ -o

clang appears to use gcc

心已入冬 提交于 2020-01-04 05:53:09
问题 When I compile a simple hello world program using clang, in the comments of the elf64 file I still find information related to GCC. Why? I'm using clang not gcc. I'm using ubuntu 16.04. username@ubuntu:~$ clang++ -stdlib=libc++ test.cpp username@ubuntu:~$ objdump --full-contents --section=.comment a.out a.out: file format elf64-x86-64 Contents of section .comment: 0000 4743433a 20285562 756e7475 20352e34 GCC: (Ubuntu 5.4 0010 2e302d36 7562756e 7475317e 31362e30 .0-6ubuntu1~16.0 0020 342e3429

Linking libc++ to CMake project on Linux

末鹿安然 提交于 2020-01-01 08:44:40
问题 I want to use libc++ together with clang on Arch Linux in CMake project. I installed libc++ and added following lines to CMakeLists.txt as said on LLVM site in Linux section of "Using libc++ in your programs": set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "-lc++abi") I have tried just "++abi" in linker's flags, but it didn't help. I need some help in figuring out what i should write in my CMakeLists.txt. 回答1: Don't forget to set the compiler to

Clang and GCC disagree in auto specifier for non-type template parameter in a casting C++17

£可爱£侵袭症+ 提交于 2020-01-01 04:04:05
问题 I basically have a class that depends on a non-type template parameter. I defined a casting so an object of non-type template parameter N can convert to another of M . I have a minimal example that can reproduce the situation: template<auto Integral> class Test{ public: typedef decltype(Integral) value_type; static constexpr value_type N = Integral; constexpr Test (const value_type& x = 0); template<auto Integral2> constexpr explicit operator Test<Integral2>() const; private: value_type n; };

Clang and GCC disagree in auto specifier for non-type template parameter in a casting C++17

吃可爱长大的小学妹 提交于 2020-01-01 04:04:01
问题 I basically have a class that depends on a non-type template parameter. I defined a casting so an object of non-type template parameter N can convert to another of M . I have a minimal example that can reproduce the situation: template<auto Integral> class Test{ public: typedef decltype(Integral) value_type; static constexpr value_type N = Integral; constexpr Test (const value_type& x = 0); template<auto Integral2> constexpr explicit operator Test<Integral2>() const; private: value_type n; };