[edk2-devel] [Patch V2 1/7] MdePkg/Include: Update Base.h to improve C++ compatibility

Michael D Kinney posted 7 patches 3 years, 3 months ago
There is a newer version of this series
[edk2-devel] [Patch V2 1/7] MdePkg/Include: Update Base.h to improve C++ compatibility
Posted by Michael D Kinney 3 years, 3 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

* Map NULL to nullptr or __null when c++ compiler is used.
* Map STATIC_ASSERT to static_assert when a c++ compiler is used.
* Typecast RETURN_SUCCESS to type RETURN_STATUS to match type used
  by all return error/warning status codes.  C++ has stricter type
  checking and found this inconsistency.

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 MdePkg/Include/Base.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index d19ddfe4bba7..d209e6de280a 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -309,7 +309,15 @@ struct _LIST_ENTRY {
 ///
 /// NULL pointer (VOID *)
 ///
+#if defined (__cplusplus)
+  #if defined (_MSC_EXTENSIONS)
+#define NULL  nullptr
+  #else
+#define NULL  __null
+  #endif
+#else
 #define NULL  ((VOID *) 0)
+#endif
 
 //
 // Null character
@@ -760,7 +768,7 @@ typedef UINTN *BASE_LIST;
 **/
 #ifdef MDE_CPU_EBC
 #define STATIC_ASSERT(Expression, Message)
-#elif defined (_MSC_EXTENSIONS)
+#elif defined (_MSC_EXTENSIONS) || defined (__cplusplus)
 #define STATIC_ASSERT  static_assert
 #else
 #define STATIC_ASSERT  _Static_assert
@@ -959,7 +967,7 @@ typedef UINTN RETURN_STATUS;
 ///
 /// The operation completed successfully.
 ///
-#define RETURN_SUCCESS  0
+#define RETURN_SUCCESS  (RETURN_STATUS)(0)
 
 ///
 /// The image failed to load.
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95965): https://edk2.groups.io/g/devel/message/95965
Mute This Topic: https://groups.io/mt/94814639/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] 回复: [Patch V2 1/7] MdePkg/Include: Update Base.h to improve C++ compatibility
Posted by gaoliming via groups.io 3 years, 3 months ago
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

> -----邮件原件-----
> 发件人: Michael D Kinney <michael.d.kinney@intel.com>
> 发送时间: 2022年11月5日 4:25
> 收件人: devel@edk2.groups.io
> 抄送: Liming Gao <gaoliming@byosoft.com.cn>; Zhiguang Liu
> <zhiguang.liu@intel.com>
> 主题: [Patch V2 1/7] MdePkg/Include: Update Base.h to improve C++
> compatibility
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134
> 
> * Map NULL to nullptr or __null when c++ compiler is used.
> * Map STATIC_ASSERT to static_assert when a c++ compiler is used.
> * Typecast RETURN_SUCCESS to type RETURN_STATUS to match type used
>   by all return error/warning status codes.  C++ has stricter type
>   checking and found this inconsistency.
> 
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
> ---
>  MdePkg/Include/Base.h | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index d19ddfe4bba7..d209e6de280a 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -309,7 +309,15 @@ struct _LIST_ENTRY {
>  ///
>  /// NULL pointer (VOID *)
>  ///
> +#if defined (__cplusplus)
> +  #if defined (_MSC_EXTENSIONS)
> +#define NULL  nullptr
> +  #else
> +#define NULL  __null
> +  #endif
> +#else
>  #define NULL  ((VOID *) 0)
> +#endif
> 
>  //
>  // Null character
> @@ -760,7 +768,7 @@ typedef UINTN *BASE_LIST;
>  **/
>  #ifdef MDE_CPU_EBC
>  #define STATIC_ASSERT(Expression, Message)
> -#elif defined (_MSC_EXTENSIONS)
> +#elif defined (_MSC_EXTENSIONS) || defined (__cplusplus)
>  #define STATIC_ASSERT  static_assert
>  #else
>  #define STATIC_ASSERT  _Static_assert
> @@ -959,7 +967,7 @@ typedef UINTN RETURN_STATUS;
>  ///
>  /// The operation completed successfully.
>  ///
> -#define RETURN_SUCCESS  0
> +#define RETURN_SUCCESS  (RETURN_STATUS)(0)
> 
>  ///
>  /// The image failed to load.
> --
> 2.37.1.windows.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#96071): https://edk2.groups.io/g/devel/message/96071
Mute This Topic: https://groups.io/mt/94885499/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-