I've never used clang before and I figured now would be as good of a time as any to familiarize myself with it. I installed the latest Windows snapshot build that integrates itself with Visual Studio.
In order to test it out, I started doing Project Euler problems. Here is the code I used to solve problem 1:
#include <iostream>
template <unsigned int m, unsigned int n>
struct Mult
{
enum { Value = 0 };
};
template <>
struct Mult < 0, 0 >
{
enum { Value = 1 };
};
template <unsigned int m>
struct Mult < m, 0 >
{
enum { Value = 1 };
};
template <unsigned int n>
struct Mult < 0, n >
{
enum { Value = 1 };
};
template < unsigned int n >
struct EulerOne
{
enum { Value = (n * Mult<n % 3, n % 5>::Value) + EulerOne<n-1>::Value };
};
template <>
struct EulerOne < 0 >
{
enum { Value = 0 };
};
using namespace std;
int main(void)
{
cout << "Sum: " << EulerOne<999>::Value << endl;
return 0;
}
Not necessarily the best code, but valid nonetheless. The problem I ran in to was with the template initialization. Microsoft's C++ compiler is locked to a recursion limit of 500 with no way to change it. clang supposedly has the -ftemplate-depth=NNN option. So I added -ftemplate-depth=1024
to the "additional options" settings for the project.
The error I get upon compiling isn't a code error, but a compiler-specific error:
1>clang-cl.exe : error : unknown argument: '-ftemplate-depth=1024'
I checked to make sure I didn't download some weird, experimental build. I even did the following:
> type "C:\Program Files (x86)\LLVM\bin\clang-cl.exe" | find "template-depth"
use -ftemplate-depth=N to increase recursive template instantiation depth
ftemplate-depth-
ftemplate-depth=
ftemplate-depth
-ftemplate-depth
I tried using -Xclang "-ftemplate-depth=1024"
and ended up with 1>CL : error : unknown argument: '-ftemplate-depth=1024'
as a compilation error.
After adding the -v
option, this is the command it tells me is going to be run:
"C:\\Program Files (x86)\\LLVM\\msbuild-bin\\CL.exe" -cc1 -triple i686-pc-windows-msvc -emit-obj -disable-free -main-file-name p1.cpp -mrelocation-model static -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -D_MT -D_DLL --dependent-lib=msvcrt --dependent-lib=oldnames -fexceptions -fcxx-exceptions -fdiagnostics-format msvc -v -gline-tables-only -dwarf-column-info -coverage-file "C:\\Users\\jsmith\\documents\\visual studio 2013\\Projects\\ProjectEulerCpp\\P1\\LLVM\\p1.obj" -resource-dir "C:\\Program Files (x86)\\LLVM\\msbuild-bin\\..\\lib\\clang\\3.6.0" -internal-isystem "C:\\Program Files (x86)\\LLVM\\msbuild-bin\\..\\lib\\clang\\3.6.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\winrt" -O2 -Wall -Wno-error -std=c++11 -fdeprecated-macro -fdebug-compilation-dir "C:\\Users\\jsmith\\documents\\visual studio 2013\\Projects\\ProjectEulerCpp\\P1" -ferror-limit 19 -fmessage-length 0 -mstackrealign -fms-extensions -fms-compatibility -fms-compatibility-version=18.0 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -ftemplate-depth=1024 -o "LLVM\\p1.obj" -x c++ p1.cpp
No matter how I slice it, I cannot get this option to work. Does anybody have any suggestions?
It seems to be
clang-cl -Xclang -ftemplate-depth -Xclang 1024 test.cpp
How I got this:
The gcc-style driver clang++
accepts -ftemplate-depth=1024
just fine, so we can look at the command line it produces when that option is specified:
C:\LLVM\bin>clang++ -v -ftemplate-depth=1024 -c test.cpp
clang version 3.5.0 (217039)
Target: i686-pc-windows-gnu
Thread model: posix
"C:\LLVM\bin\clang++.exe" -cc1 -triple i686-pc-windows-gnu -emit-obj -mrelax-al
l -disable-free -main-file-name test.cpp -mrelocation-model static -mdisable-fp-
elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -v -d
warf-column-info -coverage-file "C:\\LLVM\\bin\\test.o" -resource-dir "C:\\LLVM\
\bin\\..\\lib\\clang\\3.5.0" -fdeprecated-macro -fdebug-compilation-dir "C:\\LLV
M\\bin" -ftemplate-depth 1024 -ferror-limit 19 -fmessage-length 80 -mstackrealig
n -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnos
tics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
The point is that the option is being passed as two command line arguments, -ftemplate-depth
followed by 1024
. So applying that to clang-cl
yields -Xclang -ftemplate-depth -Xclang 1024
.