digitalmars.D.bugs - [Issue 9698] New: Template default parameters are not checked for validity
- d-bugmail puremagic.com (44/44) Mar 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9698
http://d.puremagic.com/issues/show_bug.cgi?id=9698 Summary: Template default parameters are not checked for validity Product: D Version: D1 & D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: clugdbug yahoo.com.au Even when the expression is complete garbage, for example: ---- Example1 --- struct Foo(int x = "abc" + undefined) { } Foo!(7) w; ----------------- compiles without errors. Semantic is run on the default parameters only when they are used. There are some legitimate reasons to allow the semantic pass to be run late: --- Example2 --- struct Foo( T, int x = T.sizeof) {} ----------------- but all the spec says is that "TemplateParameter specializations and default values are evaluated in the scope of the TemplateDeclaration. " It does not say WHEN they are evaluated. Further, it says "TemplateInstantances (sic!) are always performed in the scope of where the TemplateDeclaration is declared, with the addition of the template parameters being declared as aliases for their deduced types." so that the only opportunity for the TemplateDefaultExpression is become valid is via the template parameters. Checking if the default value is valid is probably not very different from checking if a template body is valid, which is beyond the capabilities of DMD at present. My feeling is the spec should explicitly state that example2 is legal. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 12 2013