www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24094] New: importC __declspec issues

https://issues.dlang.org/show_bug.cgi?id=24094

          Issue ID: 24094
           Summary: importC __declspec issues
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: spirrwell yahoo.com

Hello!

I've tried compiling both nuklear and stb_image using importC which are
single-header libraries.

This leads to some errors in corecrt_malloc.h (in the UCRT for Windows/MSVC)
that appear to perhaps be related to unsupported declspec things.

For a simple reproduction, all that is necessary is to create a C file that
includes stdlib.h and compile it with DMD.

Here are some of the errors:

C:\Program Files (x86)\Windows
Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(58): Error:
extended-decl-modifier expected
C:\Program Files (x86)\Windows
Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(58): Error: no type for
declarator before `)`
C:\Program Files (x86)\Windows
Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(65): Error:
extended-decl-modifier expected
C:\Program Files (x86)\Windows
Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(65): Error: no type for
declarator before `)`

Which that code looks something like this:

_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
_ACRTIMP _CRTALLOCATOR _CRTRESTRICT
void* __cdecl _calloc_base(
    _In_ size_t _Count,
    _In_ size_t _Size
    );

_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
_ACRTIMP _CRT_JIT_INTRINSIC _CRTALLOCATOR _CRTRESTRICT _CRT_HYBRIDPATCHABLE
void* __cdecl calloc(
    _In_ _CRT_GUARDOVERFLOW size_t _Count,
    _In_ _CRT_GUARDOVERFLOW size_t _Size
    );

Which after preprocessing might look like this:

 __declspec(allocator) __declspec(restrict)
void* __cdecl _calloc_base(
      size_t _Count,
      size_t _Size
    );

In talking with some folks on Discord about a month ago, it sounded like people
thought it was either due to the allocator or restrict declspecs here and that
they should be able to be safely ignored.

--
Aug 19 2023