1

If I run the following test script in cppyy v1.6.2 on my Ubuntu 20.04 system:

#!/usr/bin/python3

import cppyy

cppyy.cppdef("""
struct Test { 
 void test() const {
  std::cout << std::is_same<int,double>::value << std::endl; // works
  std::cout << std::is_same_v<int,double> << std::endl;      // doesn't work
 } 
};
""");

tt = cppyy.gbl.Test()
tt.test()

I get the following error message:

input_line_21:5:21: error: no member named 'is_same_v' in namespace 'std'
  std::cout << std::is_same_v<int,double> << std::endl;      // doesn't work
               ~~~~~^
input_line_21:5:34: error: expected '(' for function-style cast or type construction
  std::cout << std::is_same_v<int,double> << std::endl;      // doesn't work
                              ~~~^
Traceback (most recent call last):
  File "./test.py", line 18, in <module>
    tt = cppyy.gbl.Test()
AttributeError: <namespace cppyy.gbl at 0x45baf10> has no attribute 'Test'. Full details:
  type object '' has no attribute 'Test'
  'Test' is not a known C++ class
  'Test' is not a known C++ template
  'Test' is not a known C++ enum

Because of the line I highlighted above. Everything else works.

I know that std::is_same_v is C++17, but on the cppyy/cling webpages I found statements that C++17 is supported. What is going on? Does C++17 not work in cppyy? Can this be configured? Is there only a subset of C++17 available?

For my project C++17 is of fundamental importance...

Progman
  • 16,827
  • 6
  • 33
  • 48
Ralf Ulrich
  • 1,575
  • 9
  • 25
  • Is this happening on Windows by any chance? ref: https://cppyy.readthedocs.io/en/latest/installation.html#c-standard-with-pip –  Oct 26 '21 at 20:13
  • As I wrote on my post I use Ubuntu 20.04. I don't have Windows at hand, so I don't know. – Ralf Ulrich Oct 26 '21 at 20:16
  • Have you included type_traits before this? I never used cppy, but from https://cppyy.readthedocs.io/en/latest/starting.html. I think you need to add : cppy.include('type_traits')) – Pepijn Kramer Oct 26 '21 at 20:25

1 Answers1

4

Why use cppyy 1.6.2? Latest release is 2.1.0. A big difference between the two is a much newer version underlying Clang in the latter (the latter also makes it possible to enable c++2a, even). That said, both 1.6.2 and 2.1.0 have no problem with the above code for me, so most likely it's an installation/build issue.

First, verify whether C++17 was enabled in your install/build. E.g. like so:

$ python
>>> import cppyy
>>> cppyy.gbl.gInterpreter.ProcessLine('__cplusplus')

The result should be 201703 or higher if C++17 is enabled.

If it isn't, reinstall, e.g. with pip, assuming you still want 1.6.2 (otherwise drop the explicit version):

$ STDCXX=17 python -m pip install cppyy==1.6.2 --no-cache-dir --force-reinstall

Note that if your system compiler (used when building CPyCppyy) does not support C++17, it will still ratchet down to C++14 or C++11, as needed, even with STDCXX=17.

Wim Lavrijsen
  • 3,453
  • 1
  • 9
  • 21
  • 1
    I verified that OP:s program is working as-is when installing cppyy 2.1.0 with `STDCXX=17 python -m pip install cppyy`. – Ted Lyngmo Oct 26 '21 at 20:30
  • Aha, I just installed with pip in the first place. But the __cplusplus is 201402. While this is the reason, I am not sure, why pip did not automatically pick up the latest version directly. I try the update now. – Ralf Ulrich Oct 27 '21 at 13:52
  • It is even worse, I appologize. I had PYTHONPATH point to a very old ROOT installation with a very outdated cppyy included. This was always picked up -- regardless of what I installed with pip. Now, after – Ralf Ulrich Oct 27 '21 at 14:10