www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - redundant storage class 'const

reply "Paul D Anderson" <claude.rains msn.com> writes:
The getValueX functions below differ only in the number and 
placing of the keyword 'const'.

The compiler rejects the first (with 'const const' prefix), as 
expected (Error: redundant storage class 'const').

The second (with prefix 'const', suffix 'const') is accepted. It 
looks strange but is apparently valid code (cf Bugs 4070 & 9020).

The fourth (with multiple 'const' suffixed) does not generate an 
error. This looks like a bug to me. Is it?

public class cls {
	private int _value;

	this(int value) {
		_value = value;
     }

//	public const const int getValue1() {  // Error: redundant 
storage class 'const'
//		return _value;
//	}
	public const int getValue2() const {  // No error
		return _value;
	}
	public int getValue3() const {  // No error
		return _value;
	}
	public int getValue4() const const const {  // No error
		return _value;
	}
}

As a side note, the error message on the first function is 
succinct and comprehensible. We can probably close Bug 9422.
Jul 05 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Paul D Anderson:

 The fourth (with multiple 'const' suffixed) does not generate 
 an error. This looks like a bug to me. Is it?
The situation with accepting or not accepting those tags attached to functions is a terrible mess since several years, at ridiculous levels. Fixing that mess will cause lot of D code to break, assuming someone someday will want to fix that awful mess, but I can't assume that any more. Look at this Issue https://d.puremagic.com/issues/show_bug.cgi?id=3934 for some humorous examples fit more for the Monty Python and the Flying Circus than a serious language. Bye, bearophile
Jul 05 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 07/06/2014 12:39 AM, bearophile wrote:
 Look at this Issue https://d.puremagic.com/issues/show_bug.cgi?id=3934
 for some humorous examples fit more for the Monty Python and the Flying
 Circus than a serious language.
While there are some oddities there, many (most?) reports in that issue are invalid. I'd have preferred separate issues for unrelated cases.
Jul 05 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Timon Gehr:

 I'd have preferred separate issues for unrelated cases.
Take a look at the report date, Timon: 2010-03-11, in the meantime I have learnt a thing or two regarding reporting compiler bugs :-) Bye, bearophile
Jul 05 2014