diff --git a/src/dmd/dtoh.d b/src/dmd/dtoh.d index 75045f09d5..9b263edebf 100644 --- a/src/dmd/dtoh.d +++ b/src/dmd/dtoh.d @@ -126,7 +126,7 @@ extern(C++) void genCppHdrFiles(ref Modules ms) buf.writenl(); buf.writestringln("#pragma once"); buf.writenl(); -// buf.writestring("#include \n"); + hashInclude(buf, ""); hashInclude(buf, ""); hashInclude(buf, ""); // buf.writestring(buf, "#include \n"); @@ -149,6 +149,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif `); diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index 904d9d1a27..ceac173e8b 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include @@ -19,6 +20,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif #if !defined(_d_real) diff --git a/test/compilable/dtoh_21217.d b/test/compilable/dtoh_21217.d index 703d38cffb..8d83c963bc 100644 --- a/test/compilable/dtoh_21217.d +++ b/test/compilable/dtoh_21217.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_AliasDeclaration.d b/test/compilable/dtoh_AliasDeclaration.d index 416f521e47..401d503fa6 100644 --- a/test/compilable/dtoh_AliasDeclaration.d +++ b/test/compilable/dtoh_AliasDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_AliasDeclaration_98.d b/test/compilable/dtoh_AliasDeclaration_98.d index c5fcd584fb..e76f9d6857 100644 --- a/test/compilable/dtoh_AliasDeclaration_98.d +++ b/test/compilable/dtoh_AliasDeclaration_98.d @@ -6,6 +6,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -23,6 +24,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_AnonDeclaration.d b/test/compilable/dtoh_AnonDeclaration.d index 586c122f44..7ba9bc326f 100644 --- a/test/compilable/dtoh_AnonDeclaration.d +++ b/test/compilable/dtoh_AnonDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_CPPNamespaceDeclaration.d b/test/compilable/dtoh_CPPNamespaceDeclaration.d index 8c045ec900..d15d94d936 100644 --- a/test/compilable/dtoh_CPPNamespaceDeclaration.d +++ b/test/compilable/dtoh_CPPNamespaceDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_ClassDeclaration.d b/test/compilable/dtoh_ClassDeclaration.d index 146284b8fd..4ae0b9c205 100644 --- a/test/compilable/dtoh_ClassDeclaration.d +++ b/test/compilable/dtoh_ClassDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_StructDeclaration.d b/test/compilable/dtoh_StructDeclaration.d index 4c30e61294..e025a76787 100644 --- a/test/compilable/dtoh_StructDeclaration.d +++ b/test/compilable/dtoh_StructDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_TemplateDeclaration.d b/test/compilable/dtoh_TemplateDeclaration.d index e705d5de5c..7f9dd99a5f 100644 --- a/test/compilable/dtoh_TemplateDeclaration.d +++ b/test/compilable/dtoh_TemplateDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_VarDeclaration.d b/test/compilable/dtoh_VarDeclaration.d index ae72e68ea7..c0f76fd5d5 100644 --- a/test/compilable/dtoh_VarDeclaration.d +++ b/test/compilable/dtoh_VarDeclaration.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif #if !defined(_d_real) diff --git a/test/compilable/dtoh_cpp98_compat.d b/test/compilable/dtoh_cpp98_compat.d index e9fe4b96ff..18f393ad73 100644 --- a/test/compilable/dtoh_cpp98_compat.d +++ b/test/compilable/dtoh_cpp98_compat.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_enum.d b/test/compilable/dtoh_enum.d index 69fb0b1cbd..b893942ddf 100644 --- a/test/compilable/dtoh_enum.d +++ b/test/compilable/dtoh_enum.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_enum_cpp98.d b/test/compilable/dtoh_enum_cpp98.d index 1dbaca98a0..8f7abb80fb 100644 --- a/test/compilable/dtoh_enum_cpp98.d +++ b/test/compilable/dtoh_enum_cpp98.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_extern_type.d b/test/compilable/dtoh_extern_type.d index 5f10db8593..8841e05dc0 100644 --- a/test/compilable/dtoh_extern_type.d +++ b/test/compilable/dtoh_extern_type.d @@ -8,6 +8,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -25,6 +26,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_functions.d b/test/compilable/dtoh_functions.d index 30aea34bf9..8350a86bd0 100644 --- a/test/compilable/dtoh_functions.d +++ b/test/compilable/dtoh_functions.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_protection.d b/test/compilable/dtoh_protection.d index 44269a6768..20d045f4fa 100644 --- a/test/compilable/dtoh_protection.d +++ b/test/compilable/dtoh_protection.d @@ -8,6 +8,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -25,6 +26,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_unittest_block.d b/test/compilable/dtoh_unittest_block.d index 2c311d0f9b..103c2b8252 100644 --- a/test/compilable/dtoh_unittest_block.d +++ b/test/compilable/dtoh_unittest_block.d @@ -7,6 +7,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -24,6 +25,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/compilable/dtoh_verbose.d b/test/compilable/dtoh_verbose.d index 849431d6a6..1eab8ebec9 100644 --- a/test/compilable/dtoh_verbose.d +++ b/test/compilable/dtoh_verbose.d @@ -6,6 +6,7 @@ TEST_OUTPUT: #pragma once +#include #include #include @@ -23,6 +24,16 @@ struct _d_dynamicArray _d_dynamicArray(size_t length_in, T *ptr_in) : length(length_in), ptr(ptr_in) { } + + T& operator[](const size_t idx) { + assert(idx < length); + return ptr[idx]; + } + + const T& operator[](const size_t idx) const { + assert(idx < length); + return ptr[idx]; + } }; #endif diff --git a/test/dshell/extra-files/cpp_header_gen/app.cpp b/test/dshell/extra-files/cpp_header_gen/app.cpp index c6aa43362c..5388b0ad64 100644 --- a/test/dshell/extra-files/cpp_header_gen/app.cpp +++ b/test/dshell/extra-files/cpp_header_gen/app.cpp @@ -13,6 +13,8 @@ int main() assert(!c->s.b); assert(c->name.ptr == name); assert(c->name.length == length); + assert(c->name[1] == 'e'); + assert(const_cast(c)->name[2] == 'a'); c->verify(); assert(foo(c->s) == bar(c));