meta question建议 c++98和 c++03标签应该是同义词。提问者跟进了 Is value initialization part of the C++98 standard? If not, why was it added in the C++03 standard? ,一个很好的问题,它阐明了向 C++03 添加值初始化。将此问题视为后者的后续问题。
OP 断言现代编译器不会费心区分 C++98 和 C++03。这让我感到惊讶,因为事实证明是三个现代编译器的情况。虽然这个问题可以归结为“RTFM”,但我的搜索没有找到任何结论。
海湾合作委员会
他们的 standards页:
The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003). These standards are referred to as C++98 and C++03, respectively. GCC implements the majority of C++98 (export is a notable exception) and most of the changes in C++03. To select this standard in GCC, use one of the options -ansi, -std=c++98, or -std=c++03; ...
此外,他们的 dialect options页面说:
In C++ mode, [ansi] is equivalent to -std=c++98.
并将“c++98”和“c++03”组合在一起:
The 1998 ISO C++ standard plus the 2003 technical corrigendum and some additional defect reports. Same as -ansi for C++ code.
这似乎意味着没有办法只打开C++98模式。
clang
我为 Clang 找到的唯一东西是在他们的 manual 上,它说在 C++ Language Features 下:
clang fully implements all of standard C++98 except for exported templates (which were removed in C++11), ...
没有提到 C++03。它还指出:
clang supports the -std option, which changes what language mode clang uses. The supported modes for C are c89, gnu89, c94, c99, gnu99, c11, gnu11, and various aliases for those modes. If no -std option is specified, clang defaults to gnu11 mode. Many C99 and C11 features are supported in earlier modes as a conforming extension, with a warning.
这当然是针对他们的 C 编译器的,我找不到任何关于 C++ 编译器的文档,例如哪些选项可以有效传递给 -std
。我只是假设 Clang 反射(reflect)了 GCC 的方言选项(例如,C++03 在 Clang 上有效),尽管没有证据我不能如此肯定地说。
MSVC
据我所知,MSVC 不允许您像上面两个那样更改语言标准。在 MSDN 上搜索“C++98”没有出现任何东西。看来他们实现了 C++98/C++11,例如 Herb Sutter 所述.
问题
虽然这些问题听起来很明显,但元问题让我意识到它并不那么明显。
有没有办法让 GCC 只符合 C++98? Enforcing the C++98 standard in gcc只是链接到我所做的相同文档,而没有进一步考虑它是否真的符合 C++98。
Clang 是否符合 C++98,或者它们实际上是否符合 C++03?我在哪里可以找到这方面的相关文档?
同样适用于 MSVC。有没有办法更改 MSVC 中的语言标准以仅符合 C++98?
最佳答案
Is there a way to make GCC only conform to C++98?
没有。您已经彻底涵盖了问题中的可用标志,但没有一个可以做到这一点。
Does Clang conform to C++98 or do they actually conform to C++03? Where can I find the relevant documentation for this?
Clang 实现 C++03 减去 export
,就像 GCC:
Clang implements all of the ISO C++ 1998 standard (including the defects addressed in the ISO C++ 2003 standard) except for export (which was removed in C++11).
Same for MSVC. Is there a way to change language standards in MSVC to conform only against C++98?
没有。如您所说,您不能在 MSVC 中指定 C++ 版本。有一个编译器标志列表,这不是其中任何一个的功能。
C++03 的全部意义在于对 C++98 进行更正,从而有效地完全取代它,而不是将其作为一个新单元来遵循。想要“还原”这些修复是没有意义的。这就像要求 Windows 7 SP2† 启动到 Windows 7 SP1 模式一样。这不是任何人都愿意支持的模式。
† Fictional .
关于c++ - 在 GCC、Clang 和 MSVC 中,有什么方法可以符合 C++98 而不是 C++03 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356712/