Can someone please explain (what might be my perceived) disparity in errors in the following code? Essentially why are "//OK" okay and "//error" errors?
(Compiler is i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490))
#include <cmath>
#include <iosfwd>
template <typename T>
class TT{
char _c[sizeof(T) + static_cast<size_t>(::ceil(sizeof(T) * 0.001)) + 1]; // error: array bound is not an integer constant
//char _c[sizeof(T) + static_cast<size_t>(sizeof(T) * 0.001) + 1]; // OK
T _t;
};
class IS{
unsigned char* _u;
double _d;
};
char s[static_cast<size_t>(::ceil(sizeof(TT<IS>) * 10.0))]; // error: array bound is not an integer constant
int main(int argc, char** argv){
char a[static_cast<size_t>(10.0)]; // OK
char b[static_cast<size_t>(::ceil(sizeof(double) * 10.0))]; // OK
TT<int> it;
char c[static_cast<size_t>(::ceil(sizeof(TT<int>) * 10.0))]; // OK
TT<IS> is;
char d[static_cast<size_t>(::ceil(sizeof(TT<IS>) * 10.0))]; // OK
return 0;
}
As a side note, I am aware of C++0x: Generalized constant expression.