Closed drdanz closed 7 years ago
After some more testing, I believe this is an issue with recent gcc versions (tested with 6.2.0). I don't see this with clang 3.8.1, and I cannot reproduce this on travis
Also it does not fail C++11 is enabled
Adding -std=c++98
to the build flags fixes this issue. The problem comes from g++ defining (even if c++11/14 is not enabled) __cplusplus=201402L
and therefore the [[deprecated]]
construct is used but it is not recognized by gcc itself.
I'd say this is a bug in the compiler.
Gcc 6 switched the default c++ standard used to C++14 (https://gcc.gnu.org/gcc-6/changes.html) so the __cplusplus value make sense, the strange thing is that is not recognizing [[deprecated]].
The following code builds with -std=c++98
and -std=c++11
but not with -std=c++14
:
#if defined(__clang__)
# if ((__clang_major__ * 100) + __clang_minor__) >= 304 && __cplusplus > 201103L
# define YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED 1
# else
# define YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED 0
# endif
#elif defined(__GNUC__)
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L
# define YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED 1
# else
# define YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED 0
# endif
#endif
# ifndef YARP_DEPRECATED
# if YARP_COMPILER_CXX_ATTRIBUTE_DEPRECATED
# define YARP_DEPRECATED [[deprecated]]
# define YARP_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
# elif YARP_COMPILER_IS_GNU || YARP_COMPILER_IS_Clang
# define YARP_DEPRECATED __attribute__((__deprecated__))
# define YARP_DEPRECATED_MSG(MSG) __attribute__((__deprecated__(MSG)))
# elif YARP_COMPILER_IS_MSVC
# define YARP_DEPRECATED __declspec(deprecated)
# define YARP_DEPRECATED_MSG(MSG) __declspec(deprecated(MSG))
# else
# define YARP_DEPRECATED
# define YARP_DEPRECATED_MSG(MSG)
# endif
# endif
class __attribute__ ((visibility ("default"))) YARP_DEPRECATED foo {};
int main(){}
This also fails:
class YARP_DEPRECATED __attribute__ ((visibility ("default"))) foo {};
Both these work:
class YARP_DEPRECATED foo {};
class __attribute__ ((visibility ("default"))) foo {};
So it is the combination of the attributes that causes issues.
Clang does not have problems building this with -std=c++14
using [[gnu::visibility("default")]]
instead of __attribute__ ((visibility ("default")))
seems to solve the problem
Unfortunately [[gnu::visibility("default")]]
solves this issues for classes, but not for functions that ignore c++11 style attributes printing a warning: attribute ignored [-Wattributes]
warning and leaving out the function from the libraries.
If
YARP_CLEAN_API
is enabled andYARP_COMPILE_TESTS
is disabled, YARP build currently fails with this error:This is not currently tested on travis, and it is normally not used because tests cannot currently compile with that flag enabled, therefore if you enable tests (on by default) this flag is not used even if you enable it manually.
We should fix it, enable the build on travis and, at some point, fix the tests so that you can compile them with this flag enabled