Skip to content

Commit 731a473

Browse files
authored
Fix implicitly-deleted default constructor error on older Xcode version. (#8719)
Older versions of Clang (particularly those shipped with older Xcode versions) are more strict about the initialization of const members. According to the C++ standard, if a class has a const member that is not initialized at the point of declaration and lacks a user-provided default constructor that initializes it, the default constructor is implicitly deleted. While newer versions of Clang and other compilers may allow this if the member has a trivial default constructor (like our View struct, which has an inline initializer for its only member), older versions of Apple Clang have been known to reject this, leading to build failures when inheriting from IString (e.g., in the Name class). This change provides an explicit default constructor for IString that initializes the 'str' member, ensuring compatibility across a wider range of compiler versions.
1 parent aef8534 commit 731a473

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/support/istring.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ struct IString {
6969

7070
std::string_view view() const { return str.view(); }
7171

72-
IString() = default;
72+
// Use an explicit constructor instead of `= default` because some older
73+
// compilers (e.g. Apple Clang in older Xcode versions) delete the default
74+
// constructor if there is a const member without an in-class initializer,
75+
// even if that member's type has a default constructor.
76+
// FIXME: Use `= default` once we bump the min clang/Xcode version that
77+
// we support.
78+
IString() : str({nullptr}) {}
7379

7480
IString(View v) : str(v) {}
7581

0 commit comments

Comments
 (0)