Skip to content

Incorrect use of __has_feature in docs #1651

Open
@jwakely

Description

@jwakely

https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual#suppressing-reports says:

Exclude problematic code/test under TSan with #if defined(__has_feature) && __has_feature(thread_sanitizer).

This only works with LLVM, and is not the correct way to test it. If __has_feature is not supported, then this construct gives an error:

foo.c:1:43: error: missing binary operator before token "("
    1 | #if defined __has_feature && __has_feature(x)
      |                                           ^

The correct way to do it is:

#ifdef __has_feature
#if __has_feature(thread_sanitizer)

To correct the docs, you could replace the code font && with the non-code word "and".

For GCC, you can check whether __SANITIZE_THREAD__ is defined instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions