Thread overview |
---|
February 29, 2008 [Issue 1880] New: templates instantiated with non-constants should fail sooner | ||||
---|---|---|---|---|
| ||||
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. -- |
February 29, 2008 [Issue 1880] templates instantiated with non-constants should fail sooner | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1880 ------- Comment #1 from wbaxter@gmail.com 2008-02-28 22:08 ------- 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. -- |
July 06, 2011 [Issue 1880] templates instantiated with non-constants should fail sooner | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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 --- Comment #2 from Don <clugdbug@yahoo.com.au> 2011-07-06 08:05:37 PDT --- 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: ------- |
Copyright © 1999-2021 by the D Language Foundation