I am trying to test the version of libstdc++
because std::regex
is implemented, but largely broken, in the versions of libstdc++
distributed with GCC before version 4.9.0.
Note that:
I need to test the version of libstdc++
, not GCC because Clang also supports using libstdc++
as the standard library. This rules out testing the __GNUC_PATCHLEVEL__
, __GNUC__
, and __GNUC_MINOR__
macros .
The __GLIBCXX__
macro is a date, not a version number and does not increase monotonically . For example, GCC 4.8.4 ships with #define __GLIBCXX__ 20150426
, which is newer than the release date of GCC 4.9.0.
Is there any portable way to test the version of libstdc++
that does not depend on using GCC my compiler?
In my opinion the problem is sufficiently small to be solved by brute force.
In a header file called machine.hpp
or similar I would test that the version of the C++ Standard is at least what I need it to be (the __cplusplus
macro). Then I would add the various macro checks to reject any library that I know to be flawed.
In other words, I would take a black-list approach instead of a white-list approach.
For example:
#pragma once
#ifndef MACHINE_HPP_HEADER_GUARDS
#define MACHINE_HPP_HEADER_GUARDS
#if __cplusplus < 201103L
// Library is incompatible if it does not implement at least the C++11
// standard.
#error "I need a library that supports at least C++11."
#else
// Load an arbitrary header to ensure that the pre-processor macro is
// defined. Otherwise you will need to load this header AFTER you
// #include the header you care about.
#include <iosfwd>
#endif
#if __GLIBCXX__ == 20150422
#error "This version of GLIBCXX (20150422) has flaws in it"
#endif
// ...repeat for other versions of GLIBCXX that you know to be flawed
#endif // MACHINE_HPP_HEADER_GUARDS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.