[Issue 2383] New: default arguments can implicitly access private global variables that are not visible at call site
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 1 16:55:38 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2383
Summary: default arguments can implicitly access private global
variables that are not visible at call site
Product: D
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: accepts-invalid, spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: tomas at famolsen.dk
Consider the following testcase:
------------------------
1st module:
module privateconst1;
extern(C) int rand();
private const int abc;
static this() {
abc = rand();
}
void foo(int i = abc) {}
------------------------
2nd module:
module privateconst2;
import privateconst1;
void main()
{
foo();
}
------
this is accepted by dmd and works. however this makes it impossible for another
compiler to mark 'abc' as internal (or in C terms, static) disabling a lot of
valuable optimizations.
in the 2nd module the call to 'foo' has to load the value of 'abc' which is
private and should not be accessible.
I can't find anywhere in the spec where it says this is allowed, hence marking
both 'spec' and 'accepts-invalid'
--
More information about the Digitalmars-d-bugs
mailing list