Building CVS HEAD on MacOSX fails with the following error: $ make make[1]: Nothing to be done for `all'. llvm[1]: Compiling SmallPtrSet.cpp for Debug build /Users/andreas/build/llvmHEAD/llvm/include/llvm/ADT/SmallPtrSet.h:191: error: non-constant ‘((N | (N - 1)) + 1)’ cannot be used as template argument /Users/andreas/build/llvmHEAD/llvm/include/llvm/ADT/SmallPtrSet.h:191: error: ‘Val’ is not a member of ‘<declaration error>’ make[1]: *** [/Users/andreas/build/llvmHEAD/llvm/lib/Support/Debug/SmallPtrSet.o] Error 1 make: *** [all] Error 1
The code in question is this: template<unsigned N> struct NextPowerOfTwoH<N, false> { enum { // We could just use NextVal = N+1, but this converges faster. N|(N-1) sets // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111. NextVal = (N|(N-1)) + 1, Val = NextPowerOfTwo<NextVal>::Val }; }; It does look wrongish and stuff. Are we depending on a compiler feature here?
N certainly is a constant. what version of G++ are you compiling with?
I use the default g++ that comes with MacOSX 10.4 (g++ 4.1?). I don't have access to that computer right now, but I'll check later today. Can anyone else reproduce this? I think the compiler is wrong; I've extracted the NextPowerOfTwo stuff and tested it with g++ 3.4 and 4.1 on linux, Visual C++ 2005, and Comeau C++, and it all works. Also, I don't think that it is the "(N|(N-1))+1" part that causes the problem because I could compile small tests with similar constructs without any problems. I experimented a bit, and it seems that line 192 is needed to get the error. 191: NextVal = (N|(N-1)) + 1, 192: Val = NextPowerOfTwo<NextVal>::Val Maybe, it is the fact that NextPowerOfTwo<N>::Val is "forward declared" when referenced at line 192 that confuses the compiler (although it shouldn't)? This is all from memory right now, but I'll post more detailed information later today when I get access to my mac.
$ g++ --version powerpc-apple-darwin8-g++-4.0.0 (GCC) 4.0.0 20041026 (Apple Computer, Inc. build 4061) I've compiled the NextPowerOfTwo stuff seperately and if line 192 is changed from "Val = NextPowerOfTwo<NextVal>::Val" into "Val = 1" compilation succeds. This seems to indicate that line 192 triggers the error reported on line 191. If line 192 is changed into "Val = NextPowerOfTwo<1>::Val" I get the following error for that line: error: incomplete type ‘NextPowerOfTwo<1u>’ used in nested name specifier There is no other error reported: nothing about N or line 191.
Does it work if you change it to: Val = NextPowerOfTwo<(N|(N-1)) + 1>::Val ? -Chris
Yes, that works!
Okay, very strange compiler bug. Easy enough to work around though: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070226/045400.html Thanks! BTW, I recommend downloading the latest Xcode from developer.apple.com, there are several issues with older versions. See the Getting Started guide for details on specific broken ones. -Chris