Skip to content

Cannot use clang-tidy in combination with winrt/base.h #566

Description

The latest versions of Visual Studio 2019 have support for clang-tidy static analysis. The problem is that clang-tidy relies on clang to compile the source for the actual analysis and the generated winrt/base.h cannot be compiled with clang due to a call to co_await():

    template <typename T>
    auto get_awaiter(T&& value) noexcept -> decltype(static_cast<T&&>(value).operator co_await())
    {
        return static_cast<T&&>(value).operator co_await();
    }

    template <typename T>
    auto get_awaiter(T&& value) noexcept -> decltype(operator co_await(static_cast<T&&>(value)))
    {
        return operator co_await(static_cast<T&&>(value));
    }

winrt/base.h(8200,87): error G58EA42A4: unknown type name 'co_await' [clang-diagnostic-error]
winrt/base.h(8206,63): error G58EA42A4: unknown type name 'co_await' [clang-diagnostic-error]

As this causes clang-tidy to generate a "clang-diagnostic-error" error and not just a warning the MSBuild build of the project will fail. Using clang-tidy with WinRT is thus not possible at the moment.

Used Visual Studio version: 2019 16.6.0 Preview 1.0
Used Nuget WinRT: 2.0.200316.3

Workaround:
Wrapping these 2 functions in #ifndef __clang__ / #endif (as is done in other places in base.h) solves the problem for clang-tidy in my case. As base.h can be regenerated and is often done, this is not a good long-term solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions