March 17, 2011 Error in "Template Alias Parameter" example in the documentation | ||||
---|---|---|---|---|
| ||||
This example comes from http://digitalmars.com/d/2.0/template.html int x; template Foo(alias X) { static int* p = &X; } void test() { alias Foo!(x) bar; *bar.p = 3; // set x to 3 static int y; alias Foo!(y) abc; *abc.p = 3; // set y to 3 } Compiling this gives the following compiler errors on the line inside Foo: t.d(5): Error: non-constant expression & x t.d(5): Error: non-constant expression & y Changing static int* to enum int* fixes the compiler errors. Are these pages written using DDoc? Is it possible to extract and compile the examples to ensure they are correct? And perhaps use asserts instead of/in addition to comments where possible (Asserts are used many places already)? Executable and verifiable examples could be a useful feature as plain text documentation and examples have a tendency to rot. |
March 17, 2011 Re: Error in "Template Alias Parameter" example in the documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | simendsjo Wrote:
> Are these pages written using DDoc? Is it possible to extract and compile the examples to
> ensure they are correct? And perhaps use asserts instead of/in addition to comments where
> possible (Asserts are used many places already)?
> Executable and verifiable examples could be a useful feature as plain text documentation and
> examples have a tendency to rot.
There has been talk about getting Examples compiled as part of unit tests. Agreement on how to do that was not reached (Sometimes examples require a lot of setup code).
This example is probably old and in need of updating, file a bug report.
|
Copyright © 1999-2021 by the D Language Foundation