www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10547] New: DMD accepts function templates with no body.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10547

           Summary: DMD accepts function templates with no body.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: brian-schott cox.net



DMD compiles the following code without complaining:

int templateFunction(A, B)(A a, B b);

From the spec: "FunctionLiterals and function templates, since their function
bodies are always present, infer the pure, nothrow, and  safe attributes unless
specifically overridden."

Either the complier or the spec is wrong. The current iteration of my grammar
does not allow function bodies to be missing, since as far as I know, empty
function templates are useless aside from forcing DDoc generation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 05 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10547


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---
Current implementation allows to split template declaration and template
definition. You can place template declaration in .di file, full definition in
.d file and instantiate template with specific arguments. In module, which
imports .di file you can instantiate template if parameters match to those used
in .d file (this is limitation as due to separate compilation it is impossible
to know beforehand all potential parameters). Since instantiated function has
no body, dmd issues reference to external symbol and the trick works (in such
case compiler does not need template body but linker must find referenced
symbols). This allows to hide template definitions in D at the cost of reducing
potential possible parameters.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10547


brian-schott cox.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |



Makes sense. I'm removing "accepts-invalid" but leaving "spec". I'll have to
update my parser and grammar.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 05 2013