From 32059235df380c51ed821adbb3f75df78de4c346 Mon Sep 17 00:00:00 2001 From: Reed Wanderman-Milne Date: Thu, 9 Jan 2025 17:17:11 -0800 Subject: [PATCH] Add float8_base as friend class to FP4 and FP6 types. This fixes a compile error on Clang 12 and below. Clang had a bug where if a superclass instantiated an instance of a subclass with a constructor defined in the superclass and brought into the subclass with a using-declaration, and the constructor had at least two arguments, compilation would fail. See https://godbolt.org/z/aeP9sP5x5 for an example. The error would complain that the superclass does not have access to the subclass's protected members, despite the constructor being declared in the superclass itself. The fix is to make the superclass a friend class of the subclass. This is already done in float8.h, but wasn't done in mxfloat.h. https://github.com/openxla/xla/pull/19096 was rolled back since it added an include of mxfloat.h in TensorFlow, causing an Android TensorFlow build using Android NDK r21e to fail since this NDK uses Clang 9. PiperOrigin-RevId: 713847187 --- ml_dtypes/include/mxfloat.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ml_dtypes/include/mxfloat.h b/ml_dtypes/include/mxfloat.h index 252e8351..9298f0f0 100644 --- a/ml_dtypes/include/mxfloat.h +++ b/ml_dtypes/include/mxfloat.h @@ -35,6 +35,7 @@ namespace mxfloat_internal { template class mxfloat6_base : public float8_internal::float8_base { using Base = float8_internal::float8_base; + friend class float8_internal::float8_base; using Base::Base; public: @@ -54,6 +55,7 @@ class mxfloat6_base : public float8_internal::float8_base { template class mxfloat4_base : public float8_internal::float8_base { using Base = float8_internal::float8_base; + friend class float8_internal::float8_base; using Base::Base; public: @@ -74,6 +76,7 @@ class float6_e2m3fn : public mxfloat6_base { // Exponent: 2, Mantissa: 3, bias: 1. // Extended range: no inf, no NaN. using Base = mxfloat6_base; + friend class float8_internal::float8_base; using Base::Base; public: @@ -86,6 +89,7 @@ class float6_e3m2fn : public mxfloat6_base { // Exponent: 3, Mantissa: 2, bias: 3. // Extended range: no inf, no NaN. using Base = mxfloat6_base; + friend class float8_internal::float8_base; using Base::Base; public: @@ -98,6 +102,7 @@ class float4_e2m1fn : public mxfloat4_base { // Exponent: 2, Mantissa: 1, bias: 1. // Extended range: no inf, no NaN. using Base = mxfloat4_base; + friend class float8_internal::float8_base;; using Base::Base; public: