]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make std::is_scoped_enum work with incomplete types
authorJonathan Wakely <jwakely@redhat.com>
Thu, 8 Apr 2021 09:50:57 +0000 (10:50 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 8 Apr 2021 10:56:59 +0000 (11:56 +0100)
commit43ab1dc24abd6fded8d5bf6547f0de6851beb200
treedf06577c5809a61e0856bdb62d3613bb1c27a19d
parent67d56b272021363eb58c319ca3b73beba3a60817
libstdc++: Make std::is_scoped_enum work with incomplete types

Tim Song pointed out that using __underlying_type is ill-formed for
incomplete enumeration types, and is_scoped_enum doesn't require a
complete type. This changes the trait to check for conversion to int
instead of to the underlying type.

In order to give the correct result when the trait is used in the
enumerator-list of an incomplete type the partial specialization for
enums has an additional check that fails for incomplete types. This
assumes that an incompelte enumeration type must be an unscoped
enumeration, and so the primary template (with a std::false_type base
characteristic) can be used. This isn't necessarily true, but it is not
currently possible to refer to a scoped enumeration type before its type
is complete (PR c++/89025).

It should be possible to use requires(remove_cv_t<_Tp> __t) in the
partial specialization's assignablility check, but that currently gives
an ICE (PR c++/99968) so there is an extra partial specialization of
is_scoped_enum<const _Tp> to handle const types.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_scoped_enum<T>): Constrain partial
specialization to not match incomplete enum types. Use a
requires-expression instead of instantiating is_convertible.
(is_scoped_enum<const T>): Add as workaround for PR c++/99968.
* testsuite/20_util/is_scoped_enum/value.cc: Check with
incomplete types and opaque-enum-declarations.
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/is_scoped_enum/value.cc