Skip to content

C++ warning when testing with testthat #1672

Closed
@DavisVaughan

Description

@DavisVaughan

On Windows with R 4.2.1, testing cpp11 throws these warnings that come from testthat:

D:/a/_temp/Library/testthat/include/testthat/testthat.h: In function 'std::ostream& Catch::cout()':
D:/a/_temp/Library/testthat/include/testthat/testthat.h:145:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  145 | }
      | ^
D:/a/_temp/Library/testthat/include/testthat/testthat.h: In function 'std::ostream& Catch::cerr()':
D:/a/_temp/Library/testthat/include/testthat/testthat.h:152:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  152 | }
      | ^

It is pointing to the usage of TESTTHAT_ATTRIBUTE_HIDDEN in these two functions

TESTTHAT_ATTRIBUTE_HIDDEN
inline std::ostream& cout()
{
static testthat::r_ostream instance;
return instance;
}
TESTTHAT_ATTRIBUTE_HIDDEN
inline std::ostream& cerr()
{
static testthat::r_ostream instance;
return instance;
}

Here is the definition of that macro:

#if defined(__GNUC__) || defined(__clang__)
# define TESTTHAT_ENABLED
# define TESTTHAT_ATTRIBUTE_HIDDEN __attribute__ ((visibility("hidden")))
#else
# define TESTTHAT_ATTRIBUTE_HIDDEN
#endif

And here is the original PR where it was added 5d052fc. The original problem that prompted the addition of this macro was for Linux, and wasn't a problem on Windows, so I feel like tweaking this for Windows is safe.

Apparently __attribute__ ((visibility("hidden"))) isn't supported on Windows with the version of gcc that comes with Rtools + R 4.2.1?

This doesn't happen on R 3.6, so it probably has to do with the updated Rtools and version of gcc.

It seems to be a general issue with the MinGW version of gcc, other people worked around it by just not using the attribute, so I feel like we should do that too fmtlib/fmt#1743

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