digitalmars.D.learn - Wrong initialization of variables
Hello, Simple code:import std.stdio; mixin template DeclFlag(alias values) { static foreach(value; values) { mixin("bool has" ~ value ~ " = false;"); } } enum Key : string { First = "qwerty", Last = "zaqy" } void main() { enum data = [Key.First, Key.Last]; mixin DeclFlag!(data); static foreach(value; data) { writeln(mixin("has" ~ value)); } }The output is:true trueBut in template mixin DeclFlag all variables are inited with "false" value! Also with AST switch I get code where there aren't any lines with text "bool hasqwerty = false;" or "bool haszaqy = false;". What happens?
Apr 01 2019
On 01.04.19 18:31, Andrey wrote:Also with AST switch I get code where there aren't any lines with text "bool hasqwerty = false;" or "bool haszaqy = false;". What happens?Compiler bug. https://issues.dlang.org/show_bug.cgi?id=19479
Apr 01 2019