This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15508] Size evaluation of variable-length array seem to be skipped in some cases.


------- Additional Comments From takashi dot yano at nifty dot ne dot jp  2004-05-21 10:02 -------
(In reply to comment #1)
> Fixed in 3.4.0 by rejecting the VLA: 
> pr15508.cc: In function `void func(int)':
> pr15508.cc:7: error: `r' cannot appear in a constant-expression

(In reply to comment #11)
> The code below works well.
> 	typedef int vla[r];
> 	vla *a = new vla [2];

I think I understood better, and also noticed fundamental issue of VLA.
'int (*)[r]' and 'int (*)[r]' may have different type each other because r is 
*variable*.
Of cource both r's in expression 'int (*a)[r] = new int [2][r];' are obviously 
same.
But, generally compiler cannot determine identity of the type of 'int (*)[r]' 
which appears more than once.
Therefore, compiler should reject any code which associates VLAs declared 
individually.

However, Code1 below is not rejected by gcc/g++. Code2 seems to be valid,
but judgeing of validity is very difficult generally, and it should not be a 
role of compiler.
So Code2 should be rejected too.

Code3 can be accepted because it is asserted that r will be never changed in 
its scope by 'const'.
Code4 can also be accepted because identity of type is claimed.

Code5 reported by me should be rejected although Code6 and Code7 can be 
acceptable.

My conclusion is that it is better to improve identity check of VLA type.

Thank you.

Code1:
	int r=5;
	int a[2][r];
	r++;
	{
		int *b[r] = a;
	}

Code2:
	int r=5;
	int a[2][r];
	(codes which don't touch r)
	int *b[r] = a;

Code3:
	int const r=5;
	int a[2][r];
	(any code)
	int *b[r] = a;

Code4:
	int r=5;
	typedef int vla[r];
	vla a[2];
	(any code)
	vla *b = a;

Code5:
	void func(int r) {
		int (*a)[r] = new int [2][r];
		delete [] a;
	}


Code6:
	void func(int const r) {
		int (*a)[r] = new int [2][r];
		delete [] a;
	}

Code7:
	void func(int r) {
		typedef int vla[r];
		vla *a = new vla [2];
		delete [] a;
	}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15508


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]