Skip to content

Commit 74c06ae

Browse files
ntreldlang-bot
authored andcommitted
Fix Issue 24012 - [spec/cpp_interface] _d_dynamicArray generated by -HC not documented
1 parent 8b99ba9 commit 74c06ae

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

spec/cpp_interface.dd

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
840840

841841
$(TROW
842842
$(ARGS $(I type)$(B [)$(I dim)$(B ])),
843-
$(ARGS $(I type)$(B [)$(I dim)$(B ]))
843+
$(ARGS $(I type)$(B [)$(I dim)$(B ]) for a variable/field declaration,
844+
or $(DDSUBLINK spec/interfaceToC, passing_d_array, use `ref` for function parameter))
844845
)
845846

846847
$(TROW
@@ -850,7 +851,7 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
850851

851852
$(TROW
852853
$(ARGS $(I type)$(B [])),
853-
$(ARGS no equivalent)
854+
$(ARGS no `extern (C++)` equivalent, $(RELATIVE_LINK2 dynamic-arrays, see below))
854855
)
855856

856857
$(TROW
@@ -872,6 +873,48 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
872873
$(P These equivalents hold when the D and C++ compilers used are companions
873874
on the host platform.)
874875

876+
$(H3 $(LNAME2 dynamic-arrays, Dynamic Arrays))
877+
878+
$(P These are not supported for `extern (C++)`. For `extern (C)`, they
879+
are equivalent to a struct template. For example:)
880+
881+
---
882+
extern (C) const(char)[] slice;
883+
---
884+
885+
$(P `dmd -HC` generates the following C++ declaration:)
886+
887+
```
888+
extern "C" _d_dynamicArray< const char > slice;
889+
```
890+
$(P `_d_dynamicArray` is generated as follows:)
891+
892+
```
893+
/// Represents a D [] array
894+
template<typename T>
895+
struct _d_dynamicArray final
896+
{
897+
size_t length;
898+
T *ptr;
899+
900+
_d_dynamicArray() : length(0), ptr(NULL) { }
901+
902+
_d_dynamicArray(size_t length_in, T *ptr_in)
903+
: length(length_in), ptr(ptr_in) { }
904+
905+
T& operator[](const size_t idx) {
906+
assert(idx < length);
907+
return ptr[idx];
908+
}
909+
910+
const T& operator[](const size_t idx) const {
911+
assert(idx < length);
912+
return ptr[idx];
913+
}
914+
};
915+
```
916+
917+
875918
$(H2 $(LNAME2 packing-and-alignment, Packing and Alignment))
876919

877920
$(P D structs and unions are analogous to C's.

0 commit comments

Comments
 (0)