www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14418] New: D-style Variadic Function example does not compile


          Issue ID: 14418
           Summary: D-style Variadic Function example does not compile
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: websites
          Assignee: nobody puremagic.com
          Reporter: secondaryAccount web.de

The example for a 'D-style Variadic Function' on http://dlang.org/function.html
does not compile.

import core.vararg;

void test()
    foo(3, 4, 5);   // first variadic argument is 5

int foo(int x, int y, ...)
    int z;

    z = va_arg!int(_argptr); // z is set to 5

dmd 2.067.0 output [ dmd -main filename.d ]:
 Error: function [modulename].foo has no return statement, but is expected to
return a value of type int

same with gdc (frontend 2.065) and ldc (2.066.1).

Possible fixes:
- make foo void
- add 'return z;'

Apr 06 2015