Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ warning when testing with testthat #1672

Closed
DavisVaughan opened this issue Aug 22, 2022 · 1 comment · Fixed by #1673
Closed

C++ warning when testing with testthat #1672

DavisVaughan opened this issue Aug 22, 2022 · 1 comment · Fixed by #1673

Comments

@DavisVaughan
Copy link
Member

DavisVaughan commented Aug 22, 2022

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

@DavisVaughan
Copy link
Member Author

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

Maybe pull the definition of that macro out into something like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant