Incorrect CLANG Intellisense Error

Sysprogs forums Forums VisualGDB Incorrect CLANG Intellisense Error

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34435
    dedvalson
    Participant

    Hi,

    I am seeing a bogus intellisense error in a ESP-IDF 5.0 project. I have been able to reproduce this by taking the “Blink” example project and adding a single c++ file with the following content to the project.

    #include <esp_log.h>

    void foo() {
    ESP_LOGW("foo", "baz");
    }

    The ESP_LOGW statement has a squiggly red underscore and floating the mouse over it gives the error [Clang Intellisense] Error expected ')'

    The code compiles fine. The error is not produced in a c source file, only c++.

    I am using:

    Visual GDB 5.6R9 Build 4777

    ESP32 toolchain 11.2.0/9.2.90/r2

    ESP-IDF release/5.0

    ESP32 Debug Methods 20230309

    Visual Studio 2019 16.6.2

    I can supply a zip of the project but it is too large for file uploads. But all I did is add that single c++ file to the standard Blink project.

    Thanks,

    Don

     

    #34456
    support
    Keymaster

    Hi,

    It looks like the error is caused by the differences in the way gcc and clang handle the __VA_OPT__ syntax. ESP-IDF code was never tested with Clang, so it makes sense that it would trigger unexpected errors.

    You can work around it by patching the definition of ESP_LOG_LEVEL_LOCAL() in esp_log.h as follows:

    #ifdef __SYSPROGS_CODESENSE__
    #define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...)
    #else
    #define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do {               \
            if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
        } while(0)
    #endif

    The __SYSPROGS_CODESENSE__ macro is only defined by Clang IntelliSense, so it won’t affect the actual build, but will prevent IntelliSense from trying to parse unsupported syntax.

     

    #34457
    dedvalson
    Participant

    That was a good suggestions and pointed me in a different direction. If you look at the existing esp_log.h there are 4 places where there is a preprocessor statement as follows:

    #if defined(__cplusplus) && (__cplusplus > 201703L)

    I just changed them to:

    #if defined(__cplusplus) && (__cplusplus > 201703L) && defined(USE_VA_ARGS)

    This preserves the clang ability to make sure the arguments match the format statement.

    Thanks,

    Don

     

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.