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>: namespace views not available with clang-cl #2232

Closed
AlexGuteniev opened this issue Oct 2, 2021 · 13 comments · Fixed by #2637
Closed

<ranges>: namespace views not available with clang-cl #2232

AlexGuteniev opened this issue Oct 2, 2021 · 13 comments · Fixed by #2637
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@AlexGuteniev
Copy link
Contributor

Describe the bug
<ranges>: namespace views not available with clang-cl

Command-line test case

#include <iostream>
#include <ranges>
#include <vector>

int main()
{
    std::vector<int> ints{ 0, 1, 2, 3, 4, 5 };

    auto x = ints | std::ranges::views::transform([](auto i) { return i * i; });
}
d:\temp2>cl /std:c++latest test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.30.30528 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

test.cpp
Microsoft (R) Incremental Linker Version 14.30.30528.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj

d:\temp2>clang-cl /std:c++latest test.cpp
test.cpp(9,34): error: no member named 'views' in namespace 'std::ranges'
    auto x = ints | std::ranges::views::transform([](auto i) { return i * i; });
                    ~~~~~~~~~~~~~^
1 error generated.

Expected behavior
clang-cl should compile it

STL version

Version 17.0.0 Preview 4.1

Additional context
This is also tracked as DevCom-1544711

@cpplearner
Copy link
Contributor

cpplearner commented Oct 3, 2021

It seems that clang-cl defines _MSVC_LANG to be (at most) 201705L, which causes _HAS_CXX23 to be defined as 0 in <vcruntime.h>.

... and clang 12 maps /std:c++latest to -std=c++20. (Clang 13 understands /std:c++20 and maps /std:c++latest to -std=c++2b.)

@CaseyCarter CaseyCarter added bug Something isn't working blocked on Clang 13 labels Oct 3, 2021
@CaseyCarter
Copy link
Member

Yes, this is all related to #1814. Just like the real C++23 features, the things #1814 pushed from C++20 into C++23 (since WG21 hasn't finished them yet) need _HAS_CXX23 == 1, which it will never be for Clang 12 unless you define it yourself.

@davidhunter22
Copy link

Hi I put the origional community issue in.

So does this mean it will all just work when VS bumps its clang to 13. Looks like the're pretty close to releaseing it https://lists.llvm.org/pipermail/llvm-dev/2021-September/152932.html. I'm assume clang-cl will be changed at the same time.
If so is this a 17.1 sort of time frame?

In the mean time should I expect # define _HAS_CXX23 = 1 to work with the 17.0.0 Preview 4.1 clang compiler or will that lead to all sort of other issues.

BTW I was trying to find a was to use the libc++ standard library with clang-cl, is that possible and if so is there documentation on how?

@CaseyCarter
Copy link
Member

So does this mean it will all just work when VS bumps its clang to 13. Looks like the're pretty close to releaseing it https://lists.llvm.org/pipermail/llvm-dev/2021-September/152932.html. I'm assume clang-cl will be changed at the same time. If so is this a 17.1 sort of time frame?

We ship clang updates in VS fairly quickly, but I can't speculate on precisely when or if Clang and VS releases will happen to line up. Generally if Clang ships while VS XX.Y is in preview, we'll update clang either in XX.Y or XX.(Y+1). (clang, clang++, and clang-cl are literally the same program which changes its behavior depending on the name you invoke it by.)

In the mean time should I expect # define _HAS_CXX23 = 1 to work with the 17.0.0 Preview 4.1 clang compiler or will that lead to all sort of other issues.

Yes, manually defining _HAS_CXX23 will work fine for now - that's how we're testing C++23 features with clang.

BTW I was trying to find a was to use the libc++ standard library with clang-cl, is that possible and if so is there documentation on how?

Microsoft doesn't support using libc++ on Windows. My understanding is that libc++ has at least partial / in progress support for Windows, you'd have to ask them how mature it is or how to use it since it doesn't ship in the LLVM windows binary packages.

@CaseyCarter
Copy link
Member

Welp, this is no longer blocked on Clang 13, which has shipped, it's now blocked in 17.2p2. Clang 13 added /std:c++20 and updated the value of __cplusplus used for /std:c++20 and /std:c++latest, but still defines the same old values of _MSVC_LANG. Since vcruntime.h determines the language mode by examining _MSVC_LANG, we must continue to specify /D_HAS_CXX23 manually.

This will be corrected either when LLVM 14 ships - which will correctly define the corresponding values of _MSVC_LANG - or VS 2022 17.2p2 ships with vcruntime.h fixed to use the larger of _MSVC_LANG or __cplusplus.

Sorry for yet more delay here, clang-cl users. I miscommunicated our requirements to the clang-cl devs in the LLVM 13 cycle, but I'll be more careful next time.

@davidhunter22
Copy link

Just to make sure I understand

  1. 17.2.p2 will use Clang 13 but you will still need to add _HAS_CXX23
  2. 17.X will use Clang 14 and that will not need _HAS_CXX23. I think 14-final is March 15th so a while after that

@CaseyCarter
Copy link
Member

Just to make sure I understand

  1. 17.2.p2 will use Clang 13 but you will still need to add _HAS_CXX23
  2. 17.X will use Clang 14 and that will not need _HAS_CXX23. I think 14-final is March 15th so a while after that

Close. 17.1p2 ships Clang 13, but you still need to add _HAS_CXX23. When 17.2p2 ships, or if you build Clang 14 yourself, /std:c++latest will be enough without needing to define _HAS_CXX23.

@davidhunter22
Copy link

I think I got confused by the Changelog https://github.com/microsoft/STL/wiki/Changelog.
This does not mention Clang 13 in the 17.1 Preview 2 section but has the following in 17.2 Preview 2 "Updated Clang to 13.0.0".
Am I misunderstanding something about the meaning of the clang comments in the changelog?

@CaseyCarter
Copy link
Member

The Changelog is a list of changes to the STL specifically, not to Visual Studio in general. Our dependencies generally track what has shipped in the most recent VS preview. So when VS ships Clang 13 (in some preview) we will (soon) update the STL's required Clang version to Clang 13. If the VS change happens late in a particular cycle - as is the case here - the first STL to ship that requires Clang X may be a full minor release later than the VS that ships Clang X.

@StephanTLavavej
Copy link
Member

VS 2022 17.2 Preview 2 is now available, so this is unblocked. I believe the remaining work needed is to remove /D_HAS_CXX23 from our test matrices.

@CaseyCarter
Copy link
Member

I believe the remaining work needed is to remove /D_HAS_CXX23 from our test matrices.

IIRC, Clang configurations that currently specify /std:c++latest without /D_HAS_CXX23 should be changed to /std:c++20, and those with /D_HAS_CXX23 should simply have it removed. Whoever does this should validate that the STL (really vcruntime) defines _HAS_CXX17, _HAS_CXX20, and _HAS_CXX23 to the correct values for /std:c++14, /std:c++17, /std:c++20, and /std:c++latest after including <yvals_core.h> in all language modes with cl, clang-cl, and cl /BE.

CaseyCarter added a commit to CaseyCarter/STL that referenced this issue Apr 4, 2022
We now recognize Clang's `/std:c++20` and `/std:c++latest` modes without the "`/std:c++latest` with or without `/D_HAS_CXX23`" hack.

Fixes microsoft#2232
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Apr 16, 2022
@ambiennt
Copy link

VS 2022 17.2 Preview 2 is now available, so this is unblocked. I believe the remaining work needed is to remove /D_HAS_CXX23 from our test matrices.

I'm still having to resort to using #define _HAS_CXX23 1 to make use of any c++23 STL features in visual studio 17.7.5 with clang cl. The solution file properties explorer shows /std:c++latest being set. Am I missing something here?

@CaseyCarter
Copy link
Member

VS 2022 17.2 Preview 2 is now available, so this is unblocked. I believe the remaining work needed is to remove /D_HAS_CXX23 from our test matrices.

I'm still having to resort to using #define _HAS_CXX23 1 to make use of any c++23 STL features in visual studio 17.7.5 with clang cl. The solution file properties explorer shows /std:c++latest being set. Am I missing something here?

This is certainly unexpected. Are you certain you don't have another older clang in your path, maybe from a separate LLVM installation? Please open a new issue, and check what output clang-cl --version and where clang-cl produce from a Developer Command Prompt.

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!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants