Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<ranges>: ranges::to<array<T, N>>() strikes fear into the hearts of compilers #4141

Closed
StephanTLavavej opened this issue Nov 2, 2023 · 1 comment · Fixed by #4142
Closed
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges

Comments

@StephanTLavavej
Copy link
Member

The following code causes MSVC to run out of memory and crash (when x86-native; x64-native can get away with allocating more memory but it still appears to be infinite). Interestingly, Clang also gets trapped here, although it doesn't run out of memory. I suspect that this leads to infinite constraint recursion, which may be something we need to fix either in the Standard or our implementaton.

Click to expand environment.
C:\Temp>"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsall.bat" x86
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.8.0-pre.6.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Temp>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33129 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

C:\Temp>clang-cl -v
clang version 16.0.5
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\Llvm\bin
C:\Temp>type meow.cpp
#include <array>
#include <ranges>
#include <span>
#include <string>
using namespace std;

void TestFn(span<const wchar_t> str) {
    auto split = str | views::split('.');

    auto vals = split | ranges::to<array<wstring, 4>>();
}
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /c meow.cpp
meow.cpp
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.33129\include\type_traits(1430): fatal error C1060: compiler is out of heap space

C:\Temp>clang-cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /c meow.cpp
[*** RUNS FOREVER ***]

This code works with vector<wstring> as an argument for ranges::to.

VS 2022 17.8 Preview 6 type_traits 1430 is this line in main right now:

conjunction<is_rvalue_reference<_Ty1>, is_lvalue_reference<_Ty2>>>>,

This is part of our horrible workaround for DevCom-10095944 VSO-1577508 which I've pinged the compiler team about just now, but the fact that Clang gets trapped even though it doesn't use this workaround indicates to me that the problem lies elsewhere.

Thanks to David Lowndes for the report.

@StephanTLavavej StephanTLavavej added help wanted Extra attention is needed ranges C++20/23 ranges labels Nov 2, 2023
@cpplearner
Copy link
Contributor

Because the element type of split (wstring_view) is not convertible to the element type of array<wstring, 4>, ranges::to<C>(r | views::transform(blahblah)) is used to construct the result. However, the result of views::transform still cannot be used to construct array<wstring, 4>. It seems that the transformation is performed again, and turtles all the way down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges
Projects
None yet
2 participants