www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - D 2.066 new behavior

reply "Paul D Anderson" <claude.rains msn.com> writes:
In all previous versions through 2.066 beta 5, the following code 
compiled and ran correctly:

import std.stdio;

T add(T)(in T x, in T y)
{
	T z;
	z = x + y;
	return z;
}

void main()
{
	const double a = 1.0;
	const double b = 2.0;
	double c;
	c = add(a,b);
	writefln("c = %s", c);	// 3.0
	c = 1.0;
	writefln("c = %s", c);	// 1.0
}

 From beta 6 onward it no longer compiles. The problem seems to be 
const qualifiers being carried into the template type. Since a 
and b are const double, the function template parameter T is 
const double. So x and y are const, no problem, but z is now 
const also. The following error message is given.

T add(T)(in T x, in T y)
{
	T z;
	z = x + y;		// Error: Can't modify const expression z
	return z;
}

The same problem shows up elsewhere as 'cannot implicitly convert 
const x to x'
and 'none of the overloads are callable using argument types (x) 
const'.

Is this expected behavior that has never been enforced before, or 
is it something new?

And is anyone else having the same problem?

Paul
Aug 21 2014
parent reply "safety0ff" <safety0ff.dev gmail.com> writes:
On Friday, 22 August 2014 at 01:54:55 UTC, Paul D Anderson wrote:
 Is this expected behavior that has never been enforced before, 
 or is it something new?

 And is anyone else having the same problem?

 Paul
Looks like a regression, I've filed it here: https://issues.dlang.org/show_bug.cgi?id=13351
Aug 21 2014
parent "Paul D Anderson" <claude.rains msn.com> writes:
On Friday, 22 August 2014 at 02:26:38 UTC, safety0ff wrote:
 On Friday, 22 August 2014 at 01:54:55 UTC, Paul D Anderson 
 wrote:
 Is this expected behavior that has never been enforced before, 
 or is it something new?

 And is anyone else having the same problem?

 Paul
Looks like a regression, I've filed it here: https://issues.dlang.org/show_bug.cgi?id=13351
Seems to be a duplicate of bug 13294: https://issues.dlang.org/show_bug.cgi?id=13294
Aug 22 2014