Commits

Armin Rigo  committed ede1d10

Give an earlier error message when trying to declare a function
using exactly '(...)' as the argument list. It's not valid C.

  • Participants
  • Parent commits af978ad

Comments (0)

Files changed (2)

File cffi/cparser.py

             params[-1].type.type.names == ['__dotdotdot__'])
         if ellipsis:
             params.pop()
-        if (len(params) == 1 and
+            if not params:
+                raise api.CDefError(
+                    "%s: a function with only '(...)' as argument"
+                    " is not correct C" % (funcname or 'in expression'))
+        elif (len(params) == 1 and
             isinstance(params[0].type, pycparser.c_ast.TypeDecl) and
             isinstance(params[0].type.type, pycparser.c_ast.IdentifierType)
                 and list(params[0].type.type.names) == ['void']):

File testing/test_parsing.py

     assert C.foo.BType == '<func (), <int>, False>'
     ffi.cdef("long foo(void);", override=True)
     assert C.foo.BType == '<func (), <long>, False>'
+
+def test_cannot_have_only_variadic_part():
+    # this checks that we get a sensible error if we try "int foo(...);"
+    ffi = FFI()
+    e = py.test.raises(CDefError, ffi.cdef, "int foo(...);")
+    assert str(e.value) == \
+           "foo: a function with only '(...)' as argument is not correct C"