Bug 80165 - Constexpr tuple of variant doesn't work
Summary: Constexpr tuple of variant doesn't work
Status: RESOLVED DUPLICATE of bug 80187
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2017-03-24 01:06 UTC by gcc-bugs
Modified: 2018-05-13 10:36 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-03-24 00:00:00


Attachments
Example that a tuple of a variant can't be constructed (215 bytes, text/x-csrc)
2017-03-24 01:06 UTC, gcc-bugs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gcc-bugs 2017-03-24 01:06:08 UTC
Created attachment 41038 [details]
Example that a tuple of a variant can't be constructed

Hi gcc-team,

first of all, I'm not sure if this bug(?) should be filed here. If not please move it to the correct component.

I currently was trying to create a constexpr tuple of a constexpr variant as value, which apparently doesn't work, even though I can create a constexpr variant.

I get the following error:

```
In file included from bug_gcc_constexpr_tuple_of_variant.cpp:2:0:
/usr/local/bin/gcc-7/include/c++/7.0.1/tuple: In function ‘int main()’:
bug_gcc_constexpr_tuple_of_variant.cpp:8:51:   in constexpr expansion of ‘std::make_tuple(_Elements&& ...) [with _Elements = {const std
::variant<unsigned char, short unsigned int, unsigned int>&}]()’
bug_gcc_constexpr_tuple_of_variant.cpp:8:51:   in constexpr expansion of ‘std::tuple<std::variant<unsigned char, short unsigned int, un
signed int> >(std::forward<const std::variant<unsigned char, short unsigned int, unsigned int>&>(__args#0))’
/usr/local/bin/gcc-7/include/c++/7.0.1/tuple:609:33:   in constexpr expansion of ‘((std::tuple<std::variant<unsigned char, short unsign
ed int, unsigned int> >*)this)->std::tuple<std::variant<unsigned char, short unsigned int, unsigned int> >::<anonymous>.std::_Tuple_imp
l<0, std::variant<unsigned char, short unsigned int, unsigned int> >::_Tuple_impl(__elements#0)’
/usr/local/bin/gcc-7/include/c++/7.0.1/tuple:361:21: error: ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [w
ith long unsigned int _Idx = 0; _Head = std::variant<unsigned char, short unsigned int, unsigned int>]’ called in a constant expression
       : _Base(__head) { }
                     ^
/usr/local/bin/gcc-7/include/c++/7.0.1/tuple:125:17: note: ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [wi

th long unsigned int _Idx = 0; _Head = std::variant<unsigned char, short unsigned int, unsigned int>]’ is not usable as a constexpr fun
ction because:
       constexpr _Head_base(const _Head& __h)
                 ^~~~~~~~~~
/usr/local/bin/gcc-7/include/c++/7.0.1/tuple:126:25: error: call to non-constexpr function ‘std::variant<_Types>::variant(const std::va
riant<_Types>&) [with _Types = {unsigned char, short unsigned int, unsigned int}]’
       : _M_head_impl(__h) { }
                         ^
In file included from bug_gcc_constexpr_tuple_of_variant.cpp:3:0:
/usr/local/bin/gcc-7/include/c++/7.0.1/variant:932:7: note: ‘std::variant<_Types>::variant(const std::variant<_Types>&) [with _Types =
{unsigned char, short unsigned int, unsigned int}]’ is not usable as a constexpr function because:
       variant(const variant&) = default;
       ^~~~~~~
/usr/local/bin/gcc-7/include/c++/7.0.1/variant:399:7: note: defaulted constructor calls non-constexpr ‘std::__detail::__variant::_Varia
nt_base<_Types>::_Variant_base(const std::__detail::__variant::_Variant_base<_Types>&) [with _Types = {unsigned char, short unsigned in
t, unsigned int}]’
       _Variant_base(const _Variant_base& __rhs)
       ^~~~~~~~~~~~~
zsh: exit 1     g++-7 -std=c++1z -Wall -Wextra bug_gcc_constexpr_tuple_of_variant.cpp
```

Maybe you can tell me what I'm doing wrong.

Best regards
marehr
Comment 1 Markus Trippelsdorf 2017-03-24 15:17:03 UTC
Ville said on IRC that this issue unfortunately cannot be fix for gcc-7.
It will have to wait 'till gcc-8.
Comment 2 Ville Voutilainen 2017-03-29 14:14:18 UTC
Hmm, might be that this can be made to work before gcc 7 ships, since it's apparently just a variant copy/move constructor issue.
Comment 3 Benjamin Buch 2017-07-21 10:39:24 UTC
Same with clang, and I found the reason:

Since the first argument is std::vector, the function std::apply is called instead of my apply function …

So it's not a bug. But maybe you can add some kind hint for such errors in the compiler frontend.
Comment 4 Benjamin Buch 2017-07-21 10:40:51 UTC
Sorry, wrong thread!
Comment 5 Jakub Jelinek 2018-05-02 10:11:15 UTC
GCC 8.1 has been released.
Comment 6 Jonathan Wakely 2018-05-02 11:25:00 UTC
This is fixed in GCC 8.1 and not going to be backported to gcc-7-branch.
Comment 7 Jonathan Wakely 2018-05-02 11:56:40 UTC
This was fixed by r249706

*** This bug has been marked as a duplicate of bug 80187 ***
Comment 8 ville 2018-05-13 10:36:44 UTC
Author: ville
Date: Sun May 13 10:36:12 2018
New Revision: 260209

URL: https://gcc.gnu.org/viewcvs?rev=260209&root=gcc&view=rev
Log:
PR libstdc++/80165
* testsuite/20_util/variant/80165.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/20_util/variant/80165.cc
Modified:
    trunk/libstdc++-v3/ChangeLog