Bug 2069687 - intl: Move the Encoder and Decoder factory methods out of the Encoding class definition for C++23 compatibility. r=hsivonen

C++23 P2448R2 [1] relaxed the requirements for constexpr destructors.
In C++23, Clang makes UniquePtr's destructor automatically constexpr.
Clang eagerly instantiates its body for the local UniquePtr<Encoder>
and UniquePtr<Decoder> variables in Encoding's inline factory methods.
Encoder and Decoder are only forward-declared at that point, so the
deleter's complete-type check fails.

To resolve this, move the NewDecoder() and NewDecoder factory methods
after the Encoding class definition so they have complete class
definitions for Encoder and Decoder.

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html

MacOSX26.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:76:19: error: invalid application of 'sizeof' to an incomplete type 'mozilla::Encoder'
76 |     static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
   |                   ^~~~~~~~~~~
MacOSX26.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:300:7: note: in instantiation of member function 'std::default_delete<mozilla::Encoder>::operator()' requested here
300 |       __deleter_(__tmp);
    |       ^
MacOSX26.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:269:71: note: in instantiation of member function 'std::unique_ptr<mozilla::Encoder>::reset' requested here
269 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
    |                                                                       ^
obj-aarch64-apple-darwin25.0.0/dist/include/mozilla/Encoding.h:736:24: note: in instantiation of member function 'std::unique_ptr<mozilla::Encoder>::~unique_ptr' requested here
736 |     UniquePtr<Encoder> encoder(encoding_new_encoder(this));
    |                        ^
obj-aarch64-apple-darwin25.0.0/dist/include/mozilla/Encoding.h:28:7: note: forward declaration of 'mozilla::Encoder'
 28 | class Encoder;
    |       ^

Differential Revision: https://phabricator.services.mozilla.com/D323890
This commit is contained in:
Chris Peterson
2026-09-11 07:20:26 +00:00
committed by cpeterson@mozilla.com
parent edcf975216
commit 78cb174eb3
+24 -16
View File
@@ -645,10 +645,7 @@ class Encoding final {
* BOM sniffing may cause the returned decoder to morph into a decoder
* for UTF-8, UTF-16LE or UTF-16BE instead of this encoding.
*/
inline UniquePtr<Decoder> NewDecoder() const {
UniquePtr<Decoder> decoder(encoding_new_decoder(this));
return decoder;
}
UniquePtr<Decoder> NewDecoder() const;
/**
* Instantiates a new decoder for this encoding with BOM sniffing enabled
@@ -670,10 +667,7 @@ class Encoding final {
* (potentially malformed) input to the decoding algorithm for this
* encoding.
*/
inline UniquePtr<Decoder> NewDecoderWithBOMRemoval() const {
UniquePtr<Decoder> decoder(encoding_new_decoder_with_bom_removal(this));
return decoder;
}
UniquePtr<Decoder> NewDecoderWithBOMRemoval() const;
/**
* Instantiates a new decoder for this encoding with BOM removal
@@ -700,10 +694,7 @@ class Encoding final {
* removed the BOM, the caller should use `NewDecoderWithBOMRemoval()`
* instead of this method to cause the BOM to be removed.
*/
inline UniquePtr<Decoder> NewDecoderWithoutBOMHandling() const {
UniquePtr<Decoder> decoder(encoding_new_decoder_without_bom_handling(this));
return decoder;
}
UniquePtr<Decoder> NewDecoderWithoutBOMHandling() const;
/**
* Instantiates a new decoder for this encoding with BOM handling disabled
@@ -724,10 +715,7 @@ class Encoding final {
/**
* Instantiates a new encoder for the output encoding of this encoding.
*/
inline UniquePtr<Encoder> NewEncoder() const {
UniquePtr<Encoder> encoder(encoding_new_encoder(this));
return encoder;
}
UniquePtr<Encoder> NewEncoder() const;
/**
* Instantiates a new encoder for the output encoding of this encoding
@@ -1345,6 +1333,26 @@ class Encoder final {
Encoder& operator=(const Encoder&) = delete;
};
inline UniquePtr<Decoder> Encoding::NewDecoder() const {
UniquePtr<Decoder> decoder(encoding_new_decoder(this));
return decoder;
}
inline UniquePtr<Decoder> Encoding::NewDecoderWithBOMRemoval() const {
UniquePtr<Decoder> decoder(encoding_new_decoder_with_bom_removal(this));
return decoder;
}
inline UniquePtr<Decoder> Encoding::NewDecoderWithoutBOMHandling() const {
UniquePtr<Decoder> decoder(encoding_new_decoder_without_bom_handling(this));
return decoder;
}
inline UniquePtr<Encoder> Encoding::NewEncoder() const {
UniquePtr<Encoder> encoder(encoding_new_encoder(this));
return encoder;
}
}; // namespace mozilla
#endif // mozilla_Encoding_h