簡體   English   中英

如何在編譯時測試libstdc ++的版本,而不是GCC?

[英]How do I test the version of libstdc++, not GCC, at compile time?

我正在嘗試測試libstdc++的版本,因為std::regex在版本4.9.0之前與GCC一起發布的libstdc++版本中實現了,但很大程度上已經破壞了。

注意:

是否有任何可移植的方法來測試不依賴於使用GCC我的編譯器的libstdc++版本?

在我看來,問題足夠小,無法用蠻力解決。

在名為machine.hpp或類似的頭文件中,我將測試C ++標准的版本至少是我需要的版本( __cplusplus宏)。 然后我會添加各種宏檢查來拒絕任何我知道有缺陷的庫。

換句話說,我會采用黑名單方法而不是白名單方法。

例如:

#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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM