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

Qualification in compound return types #28

Open
phdum opened this issue Jan 20, 2020 · 0 comments
Open

Qualification in compound return types #28

phdum opened this issue Jan 20, 2020 · 0 comments

Comments

@phdum
Copy link
Member

phdum commented Jan 20, 2020

Hi,

I ran across a problem where a locally defined type was not fully qualified when it was part of a compound return type.

Here a minimal example test.hpp:

#pragma once

#include <utility>
#include <tuple>
#include <triqs/utility/first_include.hpp>

namespace test_namespace {

class test_class {
 public:
  using return_t = double;
  std::pair<return_t, double> test_function_bad() { return std::make_pair(0.0, 0.0); }
  return_t test_function_good() { return std::make_pair(0.0, 0.0); }
};

} // namespace test_namespace

If we run c++2py on this:

# Generated automatically using the command :
# c++2py tmp.hpp -N test_namespace
from cpp2py.wrap_generator import *

# The module
module = module_(full_name = "tmp", doc = r"", app_name = "tmp")

# Imports

# Add here all includes
module.add_include("tmp.hpp")

# Add here anything to add in the C++ code at the start, e.g. namespace using
module.add_preamble("""
#include <cpp2py/converters/pair.hpp>

using namespace test_namespace;
""")


# The class test_class
c = class_(
        py_type = "TestClass",  # name of the python class
        c_type = "test_namespace::test_class",   # name of the C++ class
        doc = r"""""",   # doc of the C++ class
        hdf5 = False,
)

c.add_method("""std::pair<return_t,double> test_function_bad ()""",
             doc = r"""""")

c.add_method("""test_namespace::test_class::return_t test_function_good ()""",
             doc = r"""""")

module.add_class(c)



module.generate_code()

Here return_t is not correctly qualified as part of the return type in test_function_bad(). This leads to a "use of undeclared identifier" error when compiling. Contrast to the correct behaviour in test_function_good().

I'm guessing that c++2py would need to recursively step into the compound return type to check that everything is fully qualified?

[PS: I'm using the c++2py bundled with TRIQS 2.2.x]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant