Thread overview
[Issue 10547] New: DMD accepts function templates with no body.
Jul 05, 2013
Maxim Fomin
July 05, 2013
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


--- Comment #0 from brian-schott@cox.net 2013-07-05 03:05:42 PDT ---
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: -------
July 05, 2013
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


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-07-05 03:29:14 PDT ---
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: -------
July 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10547


brian-schott@cox.net changed:

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


--- Comment #2 from brian-schott@cox.net 2013-07-05 03:38:39 PDT ---
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: -------