From f13058c55af657144f64c536c1d65f8694fbf6db Mon Sep 17 00:00:00 2001
From: kgv <kgv@opencascade.com>
Date: Thu, 10 Oct 2019 09:22:29 +0300
Subject: [PATCH] 0031044: Coding - Standard_NODISCARD should be placed before
 Standard_EXPORT

---
 src/Standard/Standard_Macro.hxx | 91 ++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 40 deletions(-)

diff --git a/src/Standard/Standard_Macro.hxx b/src/Standard/Standard_Macro.hxx
index a2ab9188a4..66120e5562 100644
--- a/src/Standard/Standard_Macro.hxx
+++ b/src/Standard/Standard_Macro.hxx
@@ -214,48 +214,61 @@
 #endif
 
 //! @def Standard_EXPORT
-//! This macro should be used in declarations of public methods 
-//! to ensure that they are exported from DLL on Windows and thus
-//! can be called from other (dependent) libraries or applications.
+//! This macro should be used in declarations of public methods
+//! to ensure that they are exported from DLL on Windows (or has "default" visibility on Linux)
+//! and thus can be called from other (dependent) libraries or applications.
 //!
-//! If macro OCCT_STATIC_BUILD is defined, then Standard_EXPORT
-//! is set to empty. 
+//! If macro OCCT_STATIC_BUILD is defined, then Standard_EXPORT is set to empty.
 
-# if defined(_WIN32) && !defined(OCCT_STATIC_BUILD) && !defined(HAVE_NO_DLL)
-
-//======================================================
-// Windows-specific definitions
-//======================================================
-
-#  ifndef Standard_EXPORT
-#   define Standard_EXPORT __declspec( dllexport )
-// For global variables :
-#   define Standard_EXPORTEXTERN __declspec( dllexport ) extern
-#   define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport )
-#  endif  /* Standard_EXPORT */
-
-#  ifndef Standard_IMPORT
-#   define Standard_IMPORT __declspec( dllimport ) extern
-#   define Standard_IMPORTC extern "C" __declspec( dllimport )
-#  endif  /* Standard_IMPORT */
-
-# else  /* UNIX */
-
-//======================================================
-// UNIX / static library definitions
-//======================================================
+//! @def Standard_LOCAL
+//! This macro should be used in declarations of private methods and classes
+//! to hide their visibility from dynamic library export symbols.
+//!
+//! Note that on Windows methods without Standard_EXPORT are considered local implicitly,
+//! while on Linux they will have "default" visibility by default until Standard_LOCAL is specified.
 
-#  ifndef Standard_EXPORT
-#   define Standard_EXPORT
-// For global variables :
-#   define Standard_EXPORTEXTERN extern
-#   define Standard_EXPORTEXTERNC extern "C"
-#  endif  /* Standard_EXPORT */
+#if defined(OCCT_STATIC_BUILD) || defined(HAVE_NO_DLL)
+  // static library (comes later)
+#elif defined(_WIN32)
+  // windows DLL
+  #ifndef Standard_EXPORT
+    #define Standard_EXPORT __declspec(dllexport)
+    #define Standard_EXPORTEXTERN __declspec(dllexport) extern
+    #define Standard_EXPORTEXTERNC extern "C" __declspec(dllexport)
+  #endif
+  #ifndef Standard_IMPORT
+    #define Standard_IMPORT __declspec(dllimport) extern
+    #define Standard_IMPORTC extern "C" __declspec(dllimport)
+  #endif
+#elif (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
+  // UNIX dynamic library
+  #ifndef Standard_LOCAL
+    #define Standard_LOCAL __attribute__((visibility("hidden")))
+  #endif
+  #ifndef Standard_EXPORT
+    #define Standard_EXPORT __attribute__((visibility("default")))
+    #define Standard_EXPORTEXTERN  extern __attribute__((visibility("default")))
+    #define Standard_EXPORTEXTERNC extern "C" __attribute__((visibility("default")))
+  #endif
+  #ifndef Standard_IMPORT
+    #define Standard_IMPORT  extern __attribute__((visibility("default")))
+    #define Standard_IMPORTC extern "C" __attribute__((visibility("default")))
+  #endif
+#endif
 
-#  ifndef Standard_IMPORT
-#   define Standard_IMPORT extern
-#   define Standard_IMPORTC extern "C"
-#  endif  /* Standard_IMPORT */
+// static library / defaults
+#ifndef Standard_LOCAL
+  #define Standard_LOCAL
+#endif
+#ifndef Standard_EXPORT
+  #define Standard_EXPORT
+  #define Standard_EXPORTEXTERN  extern
+  #define Standard_EXPORTEXTERNC extern "C"
+#endif
+#ifndef Standard_IMPORT
+  #define Standard_IMPORT  extern
+  #define Standard_IMPORTC extern "C"
+#endif
 
 // Compatibility with old SUN compilers
 
@@ -268,8 +281,6 @@
 #define	_MEMORY_H
 #endif
 
-# endif  /* _WIN32 */
-
 //! @def OCCT_UWP
 //! This macro is defined on Windows platform in the case if the code
 //! is being compiled for UWP (Universal Windows Platform).
-- 
2.22.0.windows.1

