[PATCH] [libc++] In C++11 GNU extension mode, start emulating libstdc++'s use of constexpr.

Howard Hinnant howard.hinnant at gmail.com
Wed Nov 27 15:31:52 PST 2013

On Nov 26, 2013, at 5:04 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:

> Hi rsmith, howard.hinnant,
> libstdc++ always declares various entities as constexpr if C++14 makes
> them constexpr, even in C++11 mode. To support programs which rely on this
> behavior, start applying constexpr to those entities in C++11 mode only if
> GNU extensions are enabled (i.e. -std=gnu++11).
> We have to be selective about which entities we do this for because of the
> relaxed constexpr rules in C++14.
> This patch applies the change to entities in <utility>, as well as its
> dependencies, std::move and std::forward.
> http://llvm-reviews.chandlerc.com/D2276
> Files:
>  include/__config
>  include/__tuple
>  include/type_traits
>  include/utility
>  test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp
>  test/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
>  test/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp
>  test/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp
>  test/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp
>  test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp
>  test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
>  test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp
>  test/utilities/utility/pairs/pairs.pair/default.pass.cpp
>  test/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
>  test/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp
> <D2276.1.patch>

I find myself wondering if the following would not be simpler and more flexible:

In <__config>:

#if _LIBCPP_STD_VER <= 11
#  endif
#    define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
#  endif
#  define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
#  define _LIBCPP_DEPRECATED_AFTER_CXX11 [[deprecated]]

I.e. Allow the client to define _LIBCPP_CONSTEXPR_AFTER_CXX11 however he wants.  And if he does, his definition is respected.  Otherwise it defaults to how it is currently defined with _LIBCPP_STD_VER <= 11.


More information about the cfe-commits mailing list