Skip to content

[Bug]: GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE is not accounting for the standard in which attribute is introduced #4605

Open
@maikelvdh

Description

@maikelvdh

Describe the issue

The GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE is not evaluating against the C++ standard in which an attribute is introduced. Currently the only usage is in context of GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(maybe_unused) which could lead in context of C++14 to usage maybe_unused which is only applicable from C++17 onwards. Usage of this could be leading to -Wc++17-attribute-extensions warning.

More robust approach would be therefore be:

#define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) __cplusplus >= __has_cpp_attribute(x)

Steps to reproduce the problem

Compile googletest repository from root like:

$ CXXFLAGS="-Werror -Wall -Wextra -Wpedantic" cmake -DCMAKE_CXX_STANDARD=14 . -B /tmp/gtestbuildfolder/
$ cmake --build /tmp/gtestbuildfolder/

What version of GoogleTest are you using?

1.15.2

What operating system and version are you using?

macOS Sonoma 14.6

What compiler and version are you using?

Apple clang version 15.0.0 (clang-1500.0.40.1)

What build system are you using?

cmake version 3.30.2

Additional context

No response

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