googletest icon indicating copy to clipboard operation
googletest copied to clipboard

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

Open maikelvdh opened this issue 6 months ago • 0 comments

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

maikelvdh avatar Aug 26 '24 21:08 maikelvdh