J
johnehein
#include <vector>
using namespace std;
template <typename Iter>
int
foo(Iter first, Iter last, int nn)
{
const size_t n = last - first;
double buf[n];
return 0;
}
int
main(int argc, char **argv)
{
vector<double> x;
foo(x.begin(), x.end(), argc);
return 0;
}
foo.cc:17: instantiated from here
foo.cc:9: error: size of array is not an integral constant-expression
g++ 4.2.1
Is this error specific to g++ 4.x? g++ 3.6.4 and g++ 2.9.5 have no
problems with it, but that doesn't mean they are right. Is there some
reason to expect this to fail.
There are a few interesting workarounds that point to this being
unexpected behavior... I'll post those next.
using namespace std;
template <typename Iter>
int
foo(Iter first, Iter last, int nn)
{
const size_t n = last - first;
double buf[n];
return 0;
}
int
main(int argc, char **argv)
{
vector<double> x;
foo(x.begin(), x.end(), argc);
return 0;
}
foo.cc:17: instantiated from here
foo.cc:9: error: size of array is not an integral constant-expression
g++ 4.2.1
Is this error specific to g++ 4.x? g++ 3.6.4 and g++ 2.9.5 have no
problems with it, but that doesn't mean they are right. Is there some
reason to expect this to fail.
There are a few interesting workarounds that point to this being
unexpected behavior... I'll post those next.