cppalliance / safe-cpp

Boost Software License 1.0
152 stars 13 forks source link

Fix compiler bug around variadic template #25

Closed seanbaxter closed 1 month ago

seanbaxter commented 1 month ago
#feature on safety

template<typename T+>
struct Vec {
  Vec() safe;
  void push_back(self^, T obj) safe;

  template<typename... Ts>
  void emplace_back(self^, Ts... obj) safe {
    // Direct initialization with the String(const char*) ctor.
    // This compiles, because T is unsafe-qualified.
    self.push_back(T(rel obj...));
  }
};

struct String {
  String(const char*); // Unsafe ctor.
};

int main() safe {
  // Vec has a safe constructor.
  Vec<unsafe String> vec { };

  // void Vec<unsafe String>::emplace_back(self^, const char*) safe;
  mut vec.emplace_back("A string");
}

Can't compile the vec.emplace_back call, but can call vec.place_back.

seanbaxter commented 1 month ago

Fixed in build_sep_2_2024-1.tgz