www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9698] New: Template default parameters are not checked for validity


           Summary: Template default parameters are not checked for
           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

--- Comment #0 from Don <clugdbug yahoo.com.au> 2013-03-12 03:41:49 PDT ---
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