clang

Why does GCC generate a faster program than Clang in this recursive Fibonacci code?

六月ゝ 毕业季﹏ 提交于 2019-12-23 08:04:27
问题 This is the code that I tested: #include <iostream> #include <chrono> using namespace std; #define CHRONO_NOW chrono::high_resolution_clock::now() #define CHRONO_DURATION(first,last) chrono::duration_cast<chrono::duration<double>>(last-first).count() int fib(int n) { if (n<2) return n; return fib(n-1) + fib(n-2); } int main() { auto t0 = CHRONO_NOW; cout << fib(45) << endl; cout << CHRONO_DURATION(t0, CHRONO_NOW) << endl; return 0; } Of course, there are much faster ways of calculating

Does the C++ standard specify STL implementation details for the compiler?

感情迁移 提交于 2019-12-23 07:49:17
问题 While writing an answer to this question I faced an interesting situation - the question demonstrates the scenario where one would want to put a class in an STL container but fails to do so because of a missing copy constructor/move constructor/assignment operator. In this particular case the error is triggered by std::vector::resize . I made a quick snippet as a solution and saw another answer that had provided a move constructor instead of an assignment operator and copy constructor as I

recursive template instantiation exceeded maximum depth of 256

别等时光非礼了梦想. 提交于 2019-12-23 07:37:01
问题 I was trying to rewrite the Factorial implementation using constexpr function but for some reason I have no idea why I get a compile error: recursive template instantiation exceeded maximum depth of 256 Actually I know what the error message means but what I don't is why I'm getting this error and why the code 1 using struct work but the second using function doesn't. What's the difference between them? // yes, I know it doesn't return the factorial value. First I want to make it compile

Boost test crashes on exit with Clang 4.1 (LLVM 3.1svn)

你。 提交于 2019-12-23 07:31:18
问题 Consider this simple program: #include <string> #include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "MyTest" #include <boost/test/unit_test.hpp> using namespace std; template<char* S> void Test() { BOOST_REQUIRE("Boom!" != string(S)); } char bang[] = "Bang!"; BOOST_AUTO_TEST_CASE(Boom) { char boom[] = "Boom!"; Test<bang>(); } I'm on Mac OS X v10.8.2 (Mountain Lion) and have XCode 4.5 installed. The program works when compiled with GCC, for example, gcc test.cpp -lboost

Boost test crashes on exit with Clang 4.1 (LLVM 3.1svn)

若如初见. 提交于 2019-12-23 07:31:09
问题 Consider this simple program: #include <string> #include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "MyTest" #include <boost/test/unit_test.hpp> using namespace std; template<char* S> void Test() { BOOST_REQUIRE("Boom!" != string(S)); } char bang[] = "Bang!"; BOOST_AUTO_TEST_CASE(Boom) { char boom[] = "Boom!"; Test<bang>(); } I'm on Mac OS X v10.8.2 (Mountain Lion) and have XCode 4.5 installed. The program works when compiled with GCC, for example, gcc test.cpp -lboost

How to silence or suppress gfortran (or clang?) backend in conda?

十年热恋 提交于 2019-12-23 07:26:21
问题 I have been working on building a very particular conda environment designed for python and R with cross-talk using rpy2 . The recipe I came up with that works to install the proper R packages is the following: # install_main_environment.sh now=$(date +"%T") echo "Start Time: $now" ## Create Main Environment (OSX-64) conda create -n python3 python=3 --yes source activate python3 ## Jupyter conda install jupyterlab --yes ## R conda install -c r r --yes conda install -c r r-essentials --yes

How to detect if building with address sanitizer when building with gcc 4.8?

▼魔方 西西 提交于 2019-12-23 07:25:53
问题 I'm working on a program written in C that I occasionally build with address sanitizer, basically to catch bugs. The program prints a banner in the logs when it starts up with info such as: who built it, the branch it was built on, compiler etc. I was thinking it would be nice to also spell out if the binary was built using address sanitizer. I know there's __has_feature(address_sanitizer), but that only works for clang. I tried the following simple program: #include <stdio.h> int main() {

Compilation failed for package ‘rgeos’ while using R-studio

走远了吗. 提交于 2019-12-23 04:45:29
问题 While installing R package rgeos , I typed the code below in R-studio: >install.packages("rgeos") The output shows like this: ld: framework not found R clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [rgeos.so] Error 1 ERROR: compilation failed for package ‘rgeos’ * removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgeos’ Warning in install.packages : installation of package ‘rgeos’ had non-zero exit status What's wrong with

How to compile c99-to-c89 convertor with clang?

六月ゝ 毕业季﹏ 提交于 2019-12-23 04:34:38
问题 I'm trying to compile ffmpeg in windows for VisualStudio and one of the step is to compile c99-to-c89 code with clang according to this post. I managed to create clang.exe but how I compile c99-to-c89 code with it? I changed a little bit the makefile in c99-to-c89 so CC variable points now to clang.exe compiler and not cl.exe EXT=.exe all: c99conv$(EXT) c99wrap$(EXT) CLANGDIR=C:/build CC=C:/build/bin/Release/clang.exe CFLAGS=-nologo -Z7 -D_CRT_SECURE_NO_WARNINGS=1 -Dpopen=_popen -Dunlink=

How to compile c99-to-c89 convertor with clang?

大兔子大兔子 提交于 2019-12-23 04:34:00
问题 I'm trying to compile ffmpeg in windows for VisualStudio and one of the step is to compile c99-to-c89 code with clang according to this post. I managed to create clang.exe but how I compile c99-to-c89 code with it? I changed a little bit the makefile in c99-to-c89 so CC variable points now to clang.exe compiler and not cl.exe EXT=.exe all: c99conv$(EXT) c99wrap$(EXT) CLANGDIR=C:/build CC=C:/build/bin/Release/clang.exe CFLAGS=-nologo -Z7 -D_CRT_SECURE_NO_WARNINGS=1 -Dpopen=_popen -Dunlink=