Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   error: parameter may not have variably modified type (http://www.velocityreviews.com/forums/t702395-error-parameter-may-not-have-variably-modified-type.html)

Helmut Jarausch 10-21-2009 01:17 PM

error: parameter may not have variably modified type
 
Hi,

I have got the following error message which I don't understand

branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool, size_type, const Float&)':
branch_E.cc:48882: error: parameter may not have variably modified type 'space [(((long unsigned int)(((long int)i) +
-0x00000000000000001)) + 1)]'


space V = u.get_space();
......
// The (preprocessed) failing source line is
Form proj (space(V[i]), V_new_i, "mass");


class Form has the corresponding constructor

Form (const space& X, const space& Y, const std::string& op_name,
bool locked_boundaries=false);

and

class space : public smart_pointer<spacerep> {
space(const const_space_component&);


Can anybody throw some light on this error?

Many thanks,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Victor Bazarov 10-21-2009 02:06 PM

Re: error: parameter may not have variably modified type
 
Helmut Jarausch wrote:
> I have got the following error message which I don't understand
>
> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool,
> size_type, const Float&)':
> branch_E.cc:48882: error: parameter may not have variably modified type
> 'space [(((long unsigned int)(((long int)i) + -0x00000000000000001)) + 1)]'
>
>
> space V = u.get_space();
> .....
> // The (preprocessed) failing source line is
> Form proj (space(V[i]), V_new_i, "mass");
>


When you're in the debugger, what's the value of 'V'? You're trying to
index that pointer, but are you sure it's indexable? Are you sure that
what you get from 'u.get_space()' is a valid pointer?

>
> class Form has the corresponding constructor
>
> Form (const space& X, const space& Y, const std::string& op_name,
> bool locked_boundaries=false);
>
> and
>
> class space : public smart_pointer<spacerep> {
> space(const const_space_component&);
>
>
> Can anybody throw some light on this error?


We can. And to help us help you you should start by reading the FAQ,
especially the section 5.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

James Kanze 10-21-2009 03:38 PM

Re: error: parameter may not have variably modified type
 
On Oct 21, 2:17 pm, Helmut Jarausch <jarau...@skynet.be> wrote:

> I have got the following error message which I don't understand


> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool, size_type, const Float&)':
> branch_E.cc:48882: error: parameter may not have variably modified type 'space [(((long unsigned int)(((long int)i) +
> -0x00000000000000001)) + 1)]'


Are there really more than 48882 lines in your source file?

> space V = u.get_space();
> .....
> // The (preprocessed) failing source line is
> Form proj (space(V[i]), V_new_i, "mass");


> class Form has the corresponding constructor


> Form (const space& X, const space& Y, const std::string& op_name,
> bool locked_boundaries=false);


> and


> class space : public smart_pointer<spacerep> {
> space(const const_space_component&);


> Can anybody throw some light on this error?


Not without more code. What is V[i], for example, and what is
the definition of const_space_component? (The error message
suggests that space(V[i]) is being interpreted as a declaration,
rather than an expression. I believe some older versions of g++
had a bug like this; what compiler are you using?)

--
James Kanze

Helmut Jarausch 10-21-2009 05:53 PM

Re: error: parameter may not have variably modified type
 
James Kanze wrote:
> On Oct 21, 2:17 pm, Helmut Jarausch <jarau...@skynet.be> wrote:
>
>> I have got the following error message which I don't understand

>
>> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool, size_type, const Float&)':
>> branch_E.cc:48882: error: parameter may not have variably modified type 'space [(((long unsigned int)(((long int)i) +
>> -0x00000000000000001)) + 1)]'

>
> Are there really more than 48882 lines in your source file?

Yes, the original file has only 418 lines but I have compiled the output of the preprocessor, i.e. of g++ -E ....


>
>> space V = u.get_space();
>> .....
>> // The (preprocessed) failing source line is
>> Form proj (space(V[i]), V_new_i, "mass");

>
>> class Form has the corresponding constructor

>
>> Form (const space& X, const space& Y, const std::string& op_name,
>> bool locked_boundaries=false);

>
>> and

>
>> class space : public smart_pointer<spacerep> {
>> space(const const_space_component&);

>
>> Can anybody throw some light on this error?

>
> Not without more code. What is V[i], for example, and what is
> the definition of const_space_component? (The error message
> suggests that space(V[i]) is being interpreted as a declaration,
> rather than an expression. I believe some older versions of g++
> had a bug like this; what compiler are you using?)


First, the code is not by me, but I'd like to just understand
what the compiler "thinks" is wrong here.
The compiler is gcc-4.4.2 (the latest release, I think).
The code base is quite large and meanwhile, the author only told
me that the code is accepted by gcc-4.3.x .
So, either gcc-4.4.2 has a bug here or it is stricter than gcc-4.3.x


How can space(V[i]) be a declaration. It's constructor call
with the argument V[i].
Now, V is of class space which is a specialization of smart_pointer<spacerep>
and has an operator[] (see below)

So, V[i] is an object of type space_component (since V is a non-const object).
But, class space only has a constructor accepting const const_space_component& .
Fortunately, struct const_space_component has a constructor
const_space_component(const space_component&);
such that it should be possible to convert V[i] to an object of
type const_space_component which itself is accepted by a constructor of
class space.

So, why does gcc-4.4.2 reject this? Is it a bug, after all?

Many thanks for your help,
Helmut.

class smart_pointer {
public:

// allocators:

smart_pointer (T* p = 0);
smart_pointer (const smart_pointer&);
~smart_pointer ();
smart_pointer& operator= (const smart_pointer&);

// accessors:

const T* pointer () const;
const T& data () const;
const T* operator-> () const;
const T& operator* () const;

// modifiers:

T* pointer ();
T* operator-> ();
T& data ();
T& operator* ();

};

and

class space : public smart_pointer<spacerep> {
.....
space_component operator [] (size_type i_comp);
const_space_component operator [] (size_type i_comp) const;
....
};


struct const_space_component {
typedef space::size_type size_type;
const_space_component();
const_space_component(const space& V, size_type i);
const_space_component(const space_component&);
const space* _pV;
size_type _i_comp;
};


>
> --
> James Kanze



--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Helmut Jarausch 10-21-2009 05:57 PM

Re: error: parameter may not have variably modified type
 
Victor Bazarov wrote:
.....
>> Can anybody throw some light on this error?

>
> We can. And to help us help you you should start by reading the FAQ,
> especially the section 5.
>


I knew I've delivered too few information to fully understand what's going on.
But, the code base is quite large and what's even worse, it's not by myself.
Meanwhile the author (only) told me, the code is accepted by gcc-4.3.x but
I'm using gcc-4.4.2 .
So, in a first step, I just wanted to understand the error message (what
does the compiler "think" is wrong here).

If you're interested, I've given some more code in a reply to James Kanze's
answer.

Helmut.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Johannes Schaub (litb) 10-21-2009 06:09 PM

Re: error: parameter may not have variably modified type
 
Helmut Jarausch wrote:

> Hi,
>
> I have got the following error message which I don't understand
>
> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool,
> size_type, const Float&)': branch_E.cc:48882: error: parameter may not
> have variably modified type 'space [(((long unsigned int)(((long int)i) +
> -0x00000000000000001)) + 1)]'
>
>
> space V = u.get_space();
> .....
> // The (preprocessed) failing source line is
> Form proj (space(V[i]), V_new_i, "mass");
>
>
> class Form has the corresponding constructor
>
> Form (const space& X, const space& Y, const std::string& op_name,
> bool locked_boundaries=false);
>
> and
>
> class space : public smart_pointer<spacerep> {
> space(const const_space_component&);
>
>
> Can anybody throw some light on this error?
>


The same error is given for the following snippet in 4.4.1

struct A { A(int, char const*); };
int main() {
int i = 0, *b = &i;
A a(int(b[i]), "hello");
}

That's clearly a valid piece of code. GCC fails to check the second
parameter, which surely cannot ever be a valid declaration. Notice that when
you miss it, then GCC must interpret the code as a declaration, and reject
it:

struct A { A(int, char const*); };
int main() {
int i = 0, *b = &i;
// equivalent: A a(int b[i]);
A a(int(b[i])); // error: i is not constant
}


Johannes Schaub (litb) 10-21-2009 06:48 PM

Re: error: parameter may not have variably modified type
 
Johannes Schaub (litb) wrote:

> Helmut Jarausch wrote:
>
>> Hi,
>>
>> I have got the following error message which I don't understand
>>
>> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool,
>> size_type, const Float&)': branch_E.cc:48882: error: parameter may not
>> have variably modified type 'space [(((long unsigned int)(((long int)i) +
>> -0x00000000000000001)) + 1)]'
>>
>> [...snippet...]
>>

> The same error is given for the following snippet in 4.4.1
>
> struct A { A(int, char const*); };
> int main() {
> int i = 0, *b = &i;
> A a(int(b[i]), "hello");
> }
>
> That's clearly a valid piece of code. GCC fails to check the second
> parameter, which surely cannot ever be a valid declaration. Notice that
> when you miss it, then GCC must interpret the code as a declaration, and
> reject it:
>
> struct A { A(int, char const*); };
> int main() {
> int i = 0, *b = &i;
> // equivalent: A a(int b[i]);
> A a(int(b[i])); // error: i is not constant
> }
>

There are other ways where GCC's disambiguations go mad. Consider:

int main() { int const i = 1, p[2] = {}; { int(p[i]), 0; } }

While you would expect it's a function style cast followed by a zero in a
comma operator, it is parsed as a declaration, and thus wants to parse "0"
as a name for a declaration and fails. I don't think GCC is right. It should
be parsed as an expression.

This code also fails for GCC 4.1.

Helmut Jarausch 10-21-2009 06:49 PM

Re: error: parameter may not have variably modified type
 
Johannes Schaub (litb) wrote:
> Helmut Jarausch wrote:
>
>> Hi,
>>
>> I have got the following error message which I don't understand
>>
>> branch_E.cc: In function 'void put(std::istream&, std::ostream&, bool,
>> size_type, const Float&)': branch_E.cc:48882: error: parameter may not
>> have variably modified type 'space [(((long unsigned int)(((long int)i) +
>> -0x00000000000000001)) + 1)]'
>>
>>
>> space V = u.get_space();
>> .....
>> // The (preprocessed) failing source line is
>> Form proj (space(V[i]), V_new_i, "mass");
>>
>>
>> class Form has the corresponding constructor
>>
>> Form (const space& X, const space& Y, const std::string& op_name,
>> bool locked_boundaries=false);
>>
>> and
>>
>> class space : public smart_pointer<spacerep> {
>> space(const const_space_component&);
>>
>>
>> Can anybody throw some light on this error?
>>

>
> The same error is given for the following snippet in 4.4.1
>
> struct A { A(int, char const*); };
> int main() {
> int i = 0, *b = &i;
> A a(int(b[i]), "hello");
> }
>
> That's clearly a valid piece of code. GCC fails to check the second
> parameter, which surely cannot ever be a valid declaration. Notice that when
> you miss it, then GCC must interpret the code as a declaration, and reject
> it:
>
> struct A { A(int, char const*); };
> int main() {
> int i = 0, *b = &i;
> // equivalent: A a(int b[i]);
> A a(int(b[i])); // error: i is not constant
> }
>


Does that mean, it's a bug in gcc-4.4.2 ?


Many thanks for your comments,
Helmut.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Helmut Jarausch 10-21-2009 07:45 PM

Re: error: parameter may not have variably modified type
 
Victor Bazarov wrote:
....
>> Can anybody throw some light on this error?

>
> We can. And to help us help you you should start by reading the FAQ,
> especially the section 5.


Here is a small but complete example to show the problem.
See the last 4 lines.


#include <vector>
using std::vector;
#include <string>

struct space_component;
struct const_space_component;

template <class T>
class smart_pointer {
public:

// allocators:

smart_pointer (T* p = 0);
smart_pointer (const smart_pointer&);
~smart_pointer ();
smart_pointer& operator= (const smart_pointer&);

// accessors:

const T* pointer () const;
const T& data () const;
const T* operator-> () const;
const T& operator* () const;

// modifiers:

T* pointer ();
T* operator-> ();
T& data ();
T& operator* ();

// implementation:

};

typedef int basis;

class spacerep {
public:
typedef std::vector<basis>::size_type size_type;
spacerep();
};


class space : public smart_pointer<spacerep> {
public:
// typdefs:

typedef spacerep::size_type size_type;

// allocator/deallocator:

space ();
space(const const_space_component&);

space_component operator [] (size_type i_comp);
const_space_component operator [] (size_type i_comp) const;
};

struct space_component {
typedef space::size_type size_type;
space_component();
space_component(space& V, size_type i);
};
struct const_space_component {
typedef space::size_type size_type;
const_space_component();
const_space_component(const space_component&);
};

class form {
public :
form ();
form (const space& X, const space& Y, const std::string& op_name,
bool locked_boundaries=false);

};

int main() {
space V, V_new_i;
int i=1;
form proj (space(V[i]), V_new_i, "mass");
/* error: parameter may not have variably modified type
'space [(((long unsigned int)(((long int)i) + -0x00000000000000001)) + 1)]'
*/

}

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Victor Bazarov 10-21-2009 11:01 PM

Re: error: parameter may not have variably modified type
 
Helmut Jarausch wrote:
> Victor Bazarov wrote:
> ...
>>> Can anybody throw some light on this error?

>>
>> We can. And to help us help you you should start by reading the FAQ,
>> especially the section 5.

>
> Here is a small but complete example to show the problem.
> See the last 4 lines.
>
>
> [..valid code redacted..]
>


Comeau online trial compiles your code without a problem. Obviously
there is something wrong with the compiler you are using. Try
contacting the maker[s] of it, upgrade it, downgrade it, or/and even
post to the newsgroup dedicated to that compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


All times are GMT. The time now is 01:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.