2 次代碼提交 502a6ff1ea ... 7b06b4a136

作者 SHA1 備註 提交日期
  Kajetan Johannes Hammerle 7b06b4a136 Fix gcc build 1 月之前
  Kajetan Johannes Hammerle 8243225d82 Added missing noexcept 1 月之前
共有 4 個文件被更改,包括 16 次插入10 次删除
  1. 7 6
      modules/StringJoin.cppm
  2. 1 1
      modules/ToString.cppm
  3. 6 1
      modules/Utility.cppm
  4. 2 2
      src/ToString.cpp

+ 7 - 6
modules/StringJoin.cppm

@@ -1,9 +1,10 @@
 export module Core.StringJoin;
 
 import Core.Meta;
+import Core.Types;
 
 namespace Core {
-    template<int N>
+    template<size_t N>
     struct MergedString {
         char s[N];
 
@@ -12,26 +13,26 @@ namespace Core {
         }
     };
 
-    template<int N1, int N2>
+    template<size_t N1, size_t N2>
     consteval auto mergeStringsBase(const char (&a)[N1], const char (&b)[N2]) {
         static_assert(N1 > 0);
         MergedString<N1 + N2 - 1> s;
-        for(int i = 0; i < N1; i++) {
+        for(size_t i = 0; i < N1; i++) {
             s.s[i] = a[i];
         }
-        for(int i = 0; i < N2; i++) {
+        for(size_t i = 0; i < N2; i++) {
             s.s[i + N1 - 1] = b[i];
         }
         return s;
     }
 
-    template<int N1, int N2>
+    template<size_t N1, size_t N2>
     consteval auto mergeStringsBase(
         const MergedString<N1>& a, const char (&b)[N2]) {
         return mergeStringsBase<N1, N2>(a.s, b);
     }
 
-    template<int N1, int N2>
+    template<size_t N1, size_t N2>
     consteval auto mergeStringsBase(
         const char (&a)[N1], const MergedString<N2>& b) {
         return mergeStringsBase<N1, N2>(a, b.s);

+ 1 - 1
modules/ToString.cppm

@@ -133,7 +133,7 @@ export namespace Core {
             applyPostFormat(oldIndex, index - oldIndex, format);
         }
 
-        void addChar(char c);
+        void addChar(char c) noexcept;
         void applyPostFormat(
             size_t startIndex, size_t length,
             const StringFormat& format) noexcept;

+ 6 - 1
modules/Utility.cppm

@@ -8,7 +8,6 @@ export import Core.Types;
 
 import Core.Meta;
 import Core.Std;
-import Core.New;
 
 #define SOURCE const std::source_location& l = std::source_location::current()
 
@@ -57,7 +56,13 @@ export namespace Core {
 
     template<typename T>
     T* newWithSourceN(size_t n) noexcept {
+        // GCC does not realize this is noexcept, ...
+        // checking the empty constructor instead
+#if defined(__GNUC__) && !defined(__clang__)
+        static_assert(noexcept(new(std::source_location::current()) T()));
+#else
         static_assert(noexcept(new(std::source_location::current()) T[n]));
+#endif
         return new(std::source_location::current()) T[n];
     }
 #else

+ 2 - 2
src/ToString.cpp

@@ -39,7 +39,7 @@ void Core::StringBase::toString(
 }
 
 template<typename T, typename... Args>
-static void toBuffer(char* s, size_t n, T t, Args&&... args) {
+static void toBuffer(char* s, size_t n, T t, Args&&... args) noexcept {
     std::to_chars_result r = std::to_chars(s, s + n, t, args...);
     if(r.ec == std::errc()) {
         *r.ptr = '\0';
@@ -138,7 +138,7 @@ void Core::StringBase::print() const noexcept {
     }
 }
 
-void Core::StringBase::addChar(char c) {
+void Core::StringBase::addChar(char c) noexcept {
     if(index + 1 < capacity) {
         buffer[index] = c;
         buffer[index + 1] = '\0';