redundant storage class 'const

Paul D Anderson via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 5 15:06:55 PDT 2014


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.


More information about the Digitalmars-d mailing list