Skip to content

Qualification in compound return types #28

Open
@phdum

Description

@phdum

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions