Menu

Complex macro (syntax error)

2023-09-27
2023-09-29
  • codechanger15

    codechanger15 - 2023-09-27

    Such kind of codes produce syntax error in complex c++ projects, i hope it can be fixed.

    #define R_ASSERT_CMP( value1, operation, value2, ... )                      R_ASSERT_CMP_T( value1, operation, value2, ::xray::assert_untyped, ##__VA_ARGS__ )
    
    R_ASSERT_CMP        ( error, ==, CELL_OK );
    R_ASSERT_CMP        ( slot_id, <, 3 );
    
     
  • CHR

    CHR - 2023-09-27

    Is the definition of R_ASSERT_CMP_T visible to cppcheck?

     
    • codechanger15

      codechanger15 - 2023-09-27
      Post awaiting moderation.
    • codechanger15

      codechanger15 - 2023-09-28

      Yes, no difference, it produce syntax error.

      #   define FATAL( format, ... )                                             \
              if ( ::xray::identity(true) ) {                                     \
                  static bool debug_macro_helper_ignore_always = false;           \
                  if ( !debug_macro_helper_ignore_always ) {                      \
                      XRAY_ASSERT_HELPER(                                         \
                          debug_macro_helper_ignore_always,                       \
                          ::xray::process_error_true,                             \
                          "fatal error",                                          \
                          ::xray::assert_untyped,                                 \
                          format,                                                 \
                          ##__VA_ARGS__                                           \
                      )                                                           \
                  }                                                               \
              }                                                                   \
              else (void)0
      
      #   define R_ASSERT_T( assert_type, expression, ... )                       \
              if ( ::xray::identity(true) ) {                                     \
                  static bool debug_macro_helper_ignore_always = false;           \
                  if ( !debug_macro_helper_ignore_always && !::xray::identity(expression) ) { \
                      XRAY_ASSERT_HELPER(                                         \
                          debug_macro_helper_ignore_always,                       \
                          ::xray::process_error_true,                             \
                          XRAY_MAKE_STRING(expression),                           \
                          assert_type,                                            \
                          ##__VA_ARGS__                                           \
                      )                                                           \
                  }                                                               \
                  XRAY_ANALYSIS_ASSUME( !!(expression) );                         \
              } else XRAY_ANALYSIS_ASSUME( !!(expression) )
      
      #   define R_ASSERT_CMP_T( value1, operation, value2, assert_type, ... )    \
              if ( ::xray::identity(true) ) {                                     \
                  static bool debug_macro_helper_ignore_always = false;           \
                  if ( !debug_macro_helper_ignore_always ) {                      \
                      bool debug_macro_helper_comparison_result;                  \
                      ::xray::debug::detail::string_helper fail_message;          \
                      ::xray::debug::detail::make_fail_message(                   \
                          & fail_message,                                         \
                          debug_macro_helper_comparison_result,                   \
                          ::xray::debug::detail::make_tuple( value1, value2 )     \
                          operation                                               \
                          ::xray::debug::detail::compare_helper()                 \
                      );                                                          \
                      if ( !debug_macro_helper_comparison_result )    {           \
                          fail_message.appendf    (__VA_ARGS__);                  \
                          XRAY_ASSERT_HELPER(                                     \
                              debug_macro_helper_ignore_always,                   \
                              ::xray::process_error_true,                         \
                              XRAY_MAKE_STRING(value1)                            \
                              " "                                                 \
                              XRAY_MAKE_STRING(operation)                         \
                              " "                                                 \
                              XRAY_MAKE_STRING(value2),                           \
                              assert_type,                                        \
                              "%s",                                               \
                              fail_message.c_str( )                               \
                          );                                                      \
                      }                                                           \
                  }                                                               \
                  XRAY_ANALYSIS_ASSUME( ((value1) operation (value2)) );          \
              }                                                                   \
              else                                                                \
                  XRAY_ANALYSIS_ASSUME( ((value1) operation (value2)) )
      
      
      #define R_ASSERT_CMP( value1, operation, value2, ... )                      R_ASSERT_CMP_T( value1, operation, value2, ::xray::assert_untyped, ##__VA_ARGS__ )
      
      void test() {
          R_ASSERT_CMP        ( error, ==, CELL_OK );
      }   
      
       
  • CHR

    CHR - 2023-09-28

    I just see more macros. Are those visible as well?
    You might want to look at cppcheck's preprocessor output (-E).

     
    • codechanger15

      codechanger15 - 2023-09-29

      should be visible, when it can't figure out macro args or type, cppcheck writes smth like "unknown macro", there just syntax error, so i guess it's a mistake in tool code, anyway, i just wanted to report this problem, y can google xray 2 engine 2011 or search here to test codes: g i t h u b . co m/tsnest/xray-2-2011/tree/main

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.