Manifest constants don't seem to honour the 'private' attribute when inside aggregate type definitions. Here's an example:
/* --- module1.d --- */
private enum string ModuleData = "asdfgh";
struct Structure {
static private enum string Data = "qwerty";
};
/* --- module2.d --- */
import module1;
import std.stdio;
void main() {
writeln(ModuleData); // Error: mod1.ModuleData is private (correct)
writeln(Structure.Data); // no error (incorrect)
};
I can't find any reason why this might be permitted, so it seems like a bug to me.
Tested using DMD v2.063.2 on WinXP.
Comment #1 by crunchengine — 2013-07-04T01:56:36Z
Created attachment 1228
Testcase for visibility attribute bug
A simpler testcase, visibility attribute is completely broken, it could cause big troubles...
tested on 2.063 on Windows XP, could someone test on other platforms ?
Comment #2 by henning — 2013-07-04T04:42:55Z
(In reply to comment #1)
> Created an attachment (id=1228) [details]
> Testcase for visibility attribute bug
>
> A simpler testcase, visibility attribute is completely broken, it could cause
> big troubles...
>
> tested on 2.063 on Windows XP, could someone test on other platforms ?
In D "private" and "protected" symbols are also accessible in the module they are declared in. So your test case should compile.
Comment #3 by ryan — 2014-10-31T18:17:39Z
Confirmed on DMD 2.066.0-1 on Linux. It also fails to catch the error inside an anonymous enum aggregate.
If I declare ModuleData as:
private enum { ModuleData = "asdfgh" }
it also slips by the compiler without error.