c++cppyy

cppyy and std::is_same_v (C++17)


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...


Solution

  • 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.