diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/compiler-core/slang-artifact.h | 5 | ||||
| -rw-r--r-- | source/compiler-core/slang-downstream-compiler.h | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/source/compiler-core/slang-artifact.h b/source/compiler-core/slang-artifact.h index 80db717d0..6072cdf76 100644 --- a/source/compiler-core/slang-artifact.h +++ b/source/compiler-core/slang-artifact.h @@ -5,6 +5,8 @@ #include "../core/slang-basic.h" #include "../../slang-com-helper.h" +#include <type_traits> + namespace Slang { @@ -47,7 +49,9 @@ struct CharSlice : public Slice<char> explicit CharSlice(const char* in) :Super(in, ::strlen(in)) {} CharSlice(const char* in, Count inCount) :Super(in, inCount) {} CharSlice() :Super(nullptr, 0) {} + explicit CharSlice(const String& s) :CharSlice(s.begin(), s.getLength()){}; }; +static_assert(std::is_trivially_copyable_v<CharSlice>); struct TerminatedCharSlice : public CharSlice { @@ -64,6 +68,7 @@ struct TerminatedCharSlice : public CharSlice TerminatedCharSlice(const char* in, Count inCount) :Super(in, inCount) { SLANG_ASSERT(in[inCount] == 0); } TerminatedCharSlice() :Super("", 0) {} }; +static_assert(std::is_trivially_copyable_v<TerminatedCharSlice>); /* As a rule of thumb, if we can define some aspect in a hierarchy then we should do so at the highest level. If some aspect can apply to multiple items identically we move that to a separate enum. diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h index 19f241ccf..4feffa743 100644 --- a/source/compiler-core/slang-downstream-compiler.h +++ b/source/compiler-core/slang-downstream-compiler.h @@ -16,6 +16,8 @@ #include "slang-artifact.h" #include "slang-artifact-associated.h" +#include <type_traits> + namespace Slang { @@ -133,7 +135,7 @@ bool isVersionCompatible(const T& in) NOTE! This type is trafficed across shared library boundaries and *versioned*. In particular -* The struct can only contain types that can be trivially memcpyd. +* The struct can only contain types that can be trivially memcpyd (checked by static_assert); * New fields can only be added to the end of the struct * New fields must take into account alignment/padding such that they do not share bytes in previous version sizes */ @@ -256,6 +258,7 @@ struct DownstreamCompileOptions // The debug info format to use. SlangDebugInfoFormat m_debugInfoFormat = SLANG_DEBUG_INFO_FORMAT_DEFAULT; }; +static_assert(std::is_trivially_copyable_v<DownstreamCompileOptions>); #define SLANG_ALIAS_DEPRECIATED_VERSION(name, id, firstField, lastField) \ struct name##_AliasDepreciated##id \ |
