Some questions while trying to compile Cling with full C++17

I’ve been trying to compile Cling with c++17 (as opposed to the default 14) with Windows SDK version 10.0.19041.0 to target Windows 10.0.18363 (msvc 2019) via


following the instructions here … After making a couple changes in (STLExtras.h for example) it’ll compile; however, although Clang 5 ‘support’ c++17, it seems like std::any etc weren’t introduced into LLVM until 7.0. I was trying to compile Cling with current (10) LLVM & Clang, but that gives a ton of errors. Is there any documentation as to what exactly is changed in clang to make it compatible with Cling? I tried running a file diff after doing cling-patches, but it was a lot … so figured I’d ask if anyone had any suggestions or something I missed. Thanks!


We’re planning to upgrade llvm & clang in ROOT (cling), but until then, I’m afraid there is not much you can do…

Cheers, Bertrand.

ah, ok. as long as it’s not just me!

No wait there are a couple of things I don’t understand.

std::any will be picked up from MSVC, not from clang. cling is just linking against clang, and serves as the “language processing engine” (replacing the compiler); the standard library is that of MSVC.

We build llvm with C++17 without problems on Linux. I believe MSVC always uses the newest standard, @bellenot ? So I don’t understand what you’d have to “fix” in STLExtras.h.

Now the most important part: what is the failure you see?

I’ll copy and paste what isn’t working as I want it to …

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
[cling]$ std::cout << "nothing included";
input_line_3:2:7: error: no member named 'cout' in namespace 'std'
 std::cout << "nothing included";
[cling]$ #include <Windows.h>
[cling]$ #include <iostream>
[cling]$ #include <any>
[cling]$ #include <string>
[cling]$ std::string testString = "This is a string.";
[cling]$ std::any testAny = testString;
input_line_9:2:7: error: no type named 'any' in namespace 'std'
 std::any testAny = testString;
[cling]$ std::cout << testString;
This is a string.
[cling]$ namespace one::two {int testInt = 7;}
input_line_11:1:14: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace one::two {int testInt = 7;}
              { namespace two       }

As for STLExtras.h … the llvm version included in the source pointed to by uses std::unary_function and std::binary_function (removed from c++17), so my build was failing when I passed it CMAKE_CXX_STANDARD=17.

I found a patch to one of the older root builds that fixed the issue … I thought it was this one but I’m not sure anymore.

though now I’m wondering if I’m missing some other flag … I deleted the directory but cling was compiling in MSVC with c++17 … it’s grabbing the header but clang is throwing that -Wc++17-extensions error.

I see - indeed both MSVC’s standard library and cling need to agree to use C++17.

@bellenot - what do we need to do to have cling run with C++17 - just configure with CMAKE_CXX_STANDARD?


I’ll check and let you know

The option CMAKE_CXX_STANDARD=17 is in ROOT only, I don’t see it in Cling… And the /std:c++14 flag is hard-coded in cling\CMakeLists.txt (line 287):

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14")

OK, so after changing the flag from /std:c++14 to /std:c++17, I confirm that cling doesn’t compile with the error:

llvm\src\include\llvm/ADT/STLExtras.h(60,45): error C2143: syntax error: missing ',' before '
<' [C:\Users\bellenot\build\llvm\build\tools\cling\lib\UserInterface\clingUserInterface.vcxproj]

So as I said, we will see if this got fixed in more recent version of llvm/clang once we upgrade

To get around that STLExtras.h issue I added:

namespace std {
template<class Arg1, class Arg2, class Result>
struct binary_function
using first_argument_type = Arg1;
using second_argument_type = Arg2;
using result_type = Result;

template <typename ArgumentType, typename ResultType>
struct unary_function
using argument_type = ArgumentType;
using result_type = ResultType;

which I pilfered from:

There were only a couple compilation errors after that, mostly fixed by removing a bunch of #include <unistd.h> instances. I never noticed that c++14 hardcoded in the cling cmakelists.txt … I’ll have to try again since that makes sense with the error I got.

that didn’t work. as expected, pragma silencing the -Wc++17-extensions error executed the code just removed the warning but the code still did not execute.

Can I build Root as c++17 and use Cling from there?

Also - the install guide references modifications to llvm/clang that were made to make cling run, but I couldn’t find any detail. Is that listed anywhere? Thanks!

Nope. And even if it was possible to build ROOT with c++17 on Windows, there would be no cling executable anyway.

That’s at and - you can see the commits in branches cling-patches

I’m getting a password prompt … though I’m not familiar with gits beyond consumption …

http:// should work without auth.

it’s probably because you’re internal? maybe I’m missing something but I don’t think it’s public. Closest I could find is but I don’t see any documentation of the patches in there.

How does $ git clone not work?

Apologies I think we were talking about different things … I can download your repo and compare it to vanilla llvm to see what changes were made, I was just wondering if there was any documentation of the changes.

Hopefully the git commit logs help. (I know they sometimes don’t, but I’m still hopeful.)