digitalmars.D.bugs - [Issue 1880] New: templates instantiated with non-constants should fail sooner
- d-bugmail puremagic.com (51/51) Feb 28 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1880
- d-bugmail puremagic.com (9/9) Feb 28 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1880
- d-bugmail puremagic.com (12/12) Jul 06 2011 http://d.puremagic.com/issues/show_bug.cgi?id=1880
http://d.puremagic.com/issues/show_bug.cgi?id=1880 Summary: templates instantiated with non-constants should fail sooner Product: D Version: 1.027 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: wbaxter gmail.com Or perhaps it should be called "static if(is()) allows a bogus type to pass". Here's the test case: enum Property {First=1,Second=2} struct CompileTimeCheck(Property Prop) { alias Prop prop; } struct CompileTime(Property Prop) { alias Prop prop; } struct RunTime { Property prop = Property.First; } void main() { alias CompileTime!(Property.First) CT; alias RunTime RT; static if (is(CompileTimeCheck!(CT.prop))) { pragma(msg, "CT ok"); } static if (is(CompileTimeCheck!(RT.prop))) { pragma(msg, "RT ok"); } alias CompileTimeCheck!(CT.prop) OK; // works no prob const z = OK.prop; alias CompileTimeCheck!(RT.prop) Fail; // fails if next line uncommentd //const y = Fail.prop; } This prints out both "CT ok" and "RT ok". It seems wrong to me both that RT passes the static if check and that the alias succeeds when using run-time value as a template parameter. It does fail if you try to actually access that .prop property, but it should fail sooner so that one can use static if's to determine if something is a compile-time accessible quantity or not. So far I haven't been able to figure out a way to do that, which is the ultimate objective. I have multiple structs, in some .prop is compile-time info in others it's run-time. I want to have a static if that handles the two cases differently but so far I can't figure out any way to write a working "isCompileTime!(T.prop)" template. --
Feb 28 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1880 You can also see it just by doing: Property x; static if(is(CompileTimeCheck!(x))) { pragma(msg, "CTC!(x) passed!"); } this shouldn't pass the is() check in my opinion. It's shouldn't be semantically valid to pass a non-constant runtime value to a template that requires a compile-time constant value. --
Feb 28 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1880 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |FIXED https://github.com/D-Programming-Language/dmd/commit/fc67046cf1e66182d959309fb15ef9e2d4c266b9 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 06 2011