VirtualBox

Changeset 97969 in vbox


Ignore:
Timestamp:
Jan 3, 2023 11:06:19 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155060
Message:

iprt/assertcompile.h: 4th attempt at fixing the problem that some gcc & clang versions annoyance at RTASSERTVAR being declared both within and outside RT_C_DECLS_BEGIN/END.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/assertcompile.h

    r97967 r97969  
    6767 * It has no other function and shouldn't be used.
    6868 *
    69  * GCC and IBM VisualAge C/C++ uses this, though GCC doesn't need this global
    70  * scope one as it declares it for each use.
    71  */
    72 #ifndef __GNUC__
     69 * GCC and IBM VisualAge C/C++ uses this.  GCC doesn't technicaly need this
     70 * global scope one as it declares it for each use, however things get
     71 * complicated in C++ code where most GCC and clang versions gets upset by mixed
     72 * "C" and "C++" versions of the symbol when using inside and outside
     73 * RT_C_DECLS_BEGIN/END.  The GCC 3.3.x and 3.4.x versions we use, OTOH will
     74 * always complain about unused RTASSERTVAR for each AssertCompileNS use in a
     75 * function if we declare it globally, so we don't do it for those, but we do
     76 * for 4.x+ to prevent linkage confusion.
     77 */
     78#if !defined(__cplusplus) || !defined(__GNUC__)
    7379extern int RTASSERTVAR[1];
     80#elif RT_GNUC_PREREQ(4, 0) || defined(__clang_major__) /* Not sure when they fixed the global scoping __unused__/whatever problem. */
     81RT_C_DECLS_BEGIN
     82extern int RTASSERTVAR[1];
     83RT_C_DECLS_END
    7484#endif
    7585
     
    103113 */
    104114#ifdef __GNUC__
    105 # ifdef __cplusplus /* Hack alert! Some GCC versions and clang gets upset when the macro is used both inside and outside
    106                                    extern "C". So, making the variable unqiue by means on __COUNTER__ or __LINE__.
    107                                    Note! __COUNTER__ may upset precompiled headers, but this macro only applies to
    108                                          gcc 4.2.x and older, so probably not a big issue. */
    109 #  ifdef __COUNTER__
    110 #   define AssertCompileNS(expr)            AssertCompileNS2(expr, RT_CONCAT(RTASSERTVAR, __COUNTER__))
    111 #  else
    112 #   define AssertCompileNS(expr)            AssertCompileNS2(expr, RT_CONCAT(RTASSERTVAR, __LINE__))
    113 #  endif
    114 #  define AssertCompileNS2(expr,a_VarName)  extern int a_VarName[         1    ] __attribute__((__unused__)), \
     115# define AssertCompileNS(expr)  AssertCompileNS2(expr,RTASSERTVAR)
     116# define AssertCompileNS2(expr,a_VarName)   extern int a_VarName[         1    ] __attribute__((__unused__)), \
    115117                                                       a_VarName[(expr) ? 1 : 0] __attribute__((__unused__))
    116 # else
    117 #  define AssertCompileNS(expr)  extern int RTASSERTVAR[1] __attribute__((__unused__)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((__unused__))
    118 # endif
    119118#elif defined(__IBMC__) || defined(__IBMCPP__)
    120119# define AssertCompileNS(expr)  extern int RTASSERTVAR[(expr) ? 1 : 0]
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette