[smartmontools-support] C++14/17 (will break compatibility)
Christian Rosentreter
karibu at gmx.net
Sat Feb 1 13:34:53 CET 2025
Hi Christian,
> On 01 Feb 2025, at 12:32 PM, Christian Franke <Christian.Franke at t-online.de> wrote:
[snip]
>> $ g++ --version
>> Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
>> Apple LLVM version 7.0.2 (clang-700.1.81)
>> Target: x86_64-apple-darwin14.5.0
>> Thread model: posix
>
> According to https://clang.llvm.org/cxx_status.html C++17 should be supported since Clang 5.
>
> The test in the configure script might return a false negative. Please test these commands:
>
> echo __cplusplus | g++ -E -xc++ -
> echo __cplusplus | g++ -std=c++17 -E -xc++ -
> echo __cplusplus | g++ -std=gnu++17 -E -xc++ -
>
> The last line shows the __cplusplus value, it should be 201703L if C++17 (but not C++20) is supported.
>
It seems that "c++17" as input value for -std isn't supported in Apple's official clang releases
before 9.1.0. Supposedly -std=c++1z can be used (which is a [deprecated] alias for "c++17" in later
versions, also see: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangStandards.def ),
but it only returns "201406L" in Apple's clang 7.0.2:
$ echo __cplusplus | g++ -E -xc++ -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 332 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
199711L
$ echo __cplusplus | g++ -std=c++17 -E -xc++ -
error: invalid value 'c++17' in '-std=c++17'
$ echo __cplusplus | g++ -std=gnu++17 -E -xc++ -
error: invalid value 'gnu++17' in '-std=gnu++17'
$ echo __cplusplus | g++ -std=c++1z -E -xc++ -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 360 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
201406L
$ echo __cplusplus | g++ -std=gnu++1z -E -xc++ -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 359 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
201406L
# "C++14" is supported though, same as "-std=c++1y"
# and is set to 201402L
#
$ echo __cplusplus | g++ -std=c++14 -E -xc++ -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 360 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
201402L
>> P.S.: I would prefer if smartmontools would not randomly break backwards compatibility for
>> no real reason. Not everything has to use "enhancements" of newer standards.
>
> PS: It is the very purpose of the above warning to prevent that we drop backward compatibility too early. We did this very carefully in the past and only if it provided real benefits:
> 2006: Move from C89 to C++98.
> 2021(!): Started using some nice C++11 features like in-class member initializers.
That's why I provided feedback. :-)
I'm not familiar with C++ at all (C all day, but C++ I only touch with a long stick usually), so I only can help
in this limited fashion… I can test other things, if needed. Let me know.
regards,
Christian
More information about the Smartmontools-support
mailing list