Bug 101233 - ICE when using ::ranges::v3::to<std::pmr::vector>
Summary: ICE when using ::ranges::v3::to<std::pmr::vector>
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.1.1
: P3 normal
Target Milestone: 11.2
Assignee: Patrick Palka
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2021-06-27 15:00 UTC by 欢乐的0403
Modified: 2021-07-16 22:52 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-06-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 欢乐的0403 2021-06-27 15:00:06 UTC
Try the following code:
--------
#include <vector>
#include <range/v3/action.hpp>

int main(){
    std::vector<int> v{1,2,3,4,5};
    v | ::ranges::v3::to<std::pmr::vector>;
}
--------

godbolt link:https://godbolt.org/z/oxnbad9M6
Comment 1 Martin Liška 2021-06-28 07:31:52 UTC
Am I right, the code is invalid?
Comment 2 欢乐的0403 2021-06-28 10:08:30 UTC
This stumps me. I don't know if the code is valid or not.
But these code compiles:
----
v | ::ranges::v3::to<std::vector>;
----
v | ::ranges::v3::to_vector;
----

So I guess the code is more likely to be valid?
Comment 3 Martin Liška 2021-06-28 10:26:43 UTC
Then let's mark it as ICE on valid code.
Comment 4 欢乐的0403 2021-06-28 10:34:45 UTC
Good, looking forward to it being fixed.
Comment 5 Patrick Palka 2021-07-15 16:00:20 UTC
Looks like the original testcase is indeed valid, but one needs to include <memory_resource> as well (for pmr::polymorphic_allocator).

Reduced:

template<class T, class U>
struct A { A(T, U); };

template<class T, class U>
using B = A<U, T>;

using type = decltype(B{0, 0});
Comment 6 Jonathan Wakely 2021-07-15 16:20:36 UTC
(In reply to Patrick Palka from comment #5)
> but one needs to include
> <memory_resource> as well (for pmr::polymorphic_allocator).

For libstdc++ the <vector> header only declares the pmr::vector alias, without defining prm::polymorphic_allocator. That means pmr::vector is an incomplete type unless you also include <memory_resource>.

This is permitted by the standard, and avoids paying to include <memory_resource> if you don't plan to use the pmr types.
Comment 7 GCC Commits 2021-07-16 20:21:43 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:a8b3861496bffae8b813ea196c1c5b27f79fbe69

commit r12-2378-ga8b3861496bffae8b813ea196c1c5b27f79fbe69
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jul 16 16:21:13 2021 -0400

    c++: alias CTAD in unevaluated context [PR101233]
    
    This is the alias CTAD version of the CTAD bug PR93248, and the fix is
    the same: clear cp_unevaluated_operand so that the entire chain of
    DECL_ARGUMENTS gets substituted.
    
            PR c++/101233
    
    gcc/cp/ChangeLog:
    
            * pt.c (alias_ctad_tweaks): Clear cp_unevaluated_operand for
            substituting DECL_ARGUMENTS.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/class-deduction-alias10.C: New test.
Comment 8 GCC Commits 2021-07-16 22:49:27 UTC
The releases/gcc-11 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:9107b139f4492d504df37e943882405e6aefdb7e

commit r11-8762-g9107b139f4492d504df37e943882405e6aefdb7e
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jul 16 16:21:13 2021 -0400

    c++: alias CTAD in unevaluated context [PR101233]
    
    This is the alias CTAD version of the CTAD bug PR93248, and the fix is
    the same: clear cp_unevaluated_operand so that the entire chain of
    DECL_ARGUMENTS gets substituted.
    
            PR c++/101233
    
    gcc/cp/ChangeLog:
    
            * pt.c (alias_ctad_tweaks): Clear cp_unevaluated_operand for
            substituting DECL_ARGUMENTS.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/class-deduction-alias10.C: New test.
    
    (cherry picked from commit a8b3861496bffae8b813ea196c1c5b27f79fbe69)
Comment 9 Patrick Palka 2021-07-16 22:52:46 UTC
Fixed for GCC 11.2 and 12.