clang++

Difference on address of const reference to ternary operator between clang and gcc

情到浓时终转凉″ 提交于 2019-12-01 03:51:30
问题 I have a vague idea of what's going on here... and it has to do with this but I'm wondering why clang++ and g++ handle this differently. Where is the undefined behaviour arround here? Note: this has nothing to do with templates - I just use them to make the example more compact. It's all about the type of whatever . #include <iostream> #include <vector> template <typename T> void test() { T whatever = 'c'; const char a = 'a'; std::cout << "begin: " << (void*)&a << std::endl; const char & me =

What could cause clang to not find the unordered_map header?

空扰寡人 提交于 2019-11-30 20:44:40
I'm trying to compile a program I found on the web using Clang++. The Makefile generates this command: clang++ -c -arch x86_64 -msse3 -std=c++11 -stdlib=libstdc++ -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-non-virtual-dtor -Wno-exit-time-destructors -Wformat -Wmissing-braces -Wparentheses -Wno-switch -Wunused-function -Wunused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-empty-body -Wuninitialized -Wunknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wno-shorten-64-to-32 -Wenum

template template parameters and clang

 ̄綄美尐妖づ 提交于 2019-11-30 20:34:44
I have had problems (possibly mine) with template template parameters and clang. The following toy example compiles and runs under g++ 4.7.0, not clang++ 3.0 (based on LLVM 3.0), both ubuntu 12.04. Toy example (test_1.cpp): #include <iostream> #include <memory> struct AFn { void operator()() { ; // do something } }; template<typename T> struct impl { T *backpointer_; }; template<typename S, template <typename> class T> struct implT { T<S> *backpointer_; }; template<typename> class AClass; template<> struct implT<AFn, AClass> { implT(std::string message) : message_(message) {} void operator()()

clang 3.6 fold expression left/right

时光毁灭记忆、已成空白 提交于 2019-11-30 19:42:06
I'm trying the fold expression with clang 3.6 '--std=c++1z', but something I don't quite get. The function that I'm testing is: auto minus = [](auto... args) { return (args - ...); }; ... std::cout << minus(10, 3, 2) << std::endl; according to n4191 , I'm expecting it expands as a left fold to (10 - 3) - 2 which gives result 5, however, the result is 9, which seems to be a right fold expansion, i.e. 10 - (3 - 2) Am I missing anything or mis-understand n4191? Thanks n4191 was revised by n4295 . According to that, an expression of the form (e op ...) is a unary right fold , and that is expanded

clang 4 build error on <functional> with c++1z

强颜欢笑 提交于 2019-11-30 19:35:18
I just updated my arch linux system to the latest which includes gcc 7.1.1. Trying to build this: #include <functional> int main(int argc, char** argv) { return 1; } using the command clang++ main.cpp -std=c++1z results in the error: In file included from main.cpp:1: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/unordered_map:47: In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1

How to force clang to use some library by default?

和自甴很熟 提交于 2019-11-30 17:25:17
I build clang by clang against libc++ , libc++abi , compiler-rt in the following steps: To download (and update) llvm and sub-projects I use the following script: svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm cd llvm/tools svn co http://llvm.org/svn/llvm-project/cfe/trunk clang svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk clang/tools/extra svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb svn co http://llvm.org/svn/llvm-project/lld/trunk lld svn co http://llvm.org/svn/llvm-project/polly/trunk polly cd ../projects/ svn co http://llvm.org/svn/llvm-project

Prevent standard functions outside of std namespace

十年热恋 提交于 2019-11-30 17:20:15
I am using only header files specific to C++ (e.g. <cstdlib> ), however I still get globally-declared functions, and not just functions in the std namespace. Is there a way, perhaps a compiler switch, to prevent that? For example, the following code: #include <cstdlib> float random() { return 0.0f; } int main() { return 0; } Fails to compile under linux, with the following error: > g++ -c main.cpp main.o main.cpp: In function ‘float random()’: main.cpp:2:14: error: new declaration ‘float random()’ /usr/include/stdlib.h:327:17: error: ambiguates old declaration ‘long int random()’ or > clang++

Prevent standard functions outside of std namespace

一笑奈何 提交于 2019-11-30 16:38:01
问题 I am using only header files specific to C++ (e.g. <cstdlib> ), however I still get globally-declared functions, and not just functions in the std namespace. Is there a way, perhaps a compiler switch, to prevent that? For example, the following code: #include <cstdlib> float random() { return 0.0f; } int main() { return 0; } Fails to compile under linux, with the following error: > g++ -c main.cpp main.o main.cpp: In function ‘float random()’: main.cpp:2:14: error: new declaration ‘float

default argument, gcc vs clang

a 夏天 提交于 2019-11-30 16:29:23
问题 Code looks like: struct Foo { Foo(const char *); }; Foo::Foo(const char *str = 0) { } VS 2013 and gcc 4.8.0 accept such code, while clang 3.3 reject such code with: error: addition of default argument on redeclaration makes this constructor a default constructor who is right from standard (C++03 and C++11) point of view? Note: I like clang's choice too, but I going to report bug to gcc and visual studio, and if this is not correct from standard point of view, this helps to convince compiler's

Misaligned address using virtual inheritance

我怕爱的太早我们不能终老 提交于 2019-11-30 14:31:07
The following apparently valid code produces a misaligned address runtime error using the UndefinedBehaviorSanitizer sanitiser. #include <memory> #include <functional> struct A{ std::function<void()> data; // seems to occur only if data is a std::function } ; struct B{ char data; // occurs only if B contains a member variable }; struct C:public virtual A,public B{ }; struct D:public virtual C{ }; void test(){ std::make_shared<D>(); } int main(){ test(); return 0; } Compiling and executing on a macbook with clang++ -fsanitize=undefined --std=c++11 ./test.cpp && ./a.out produces the output