Skip to content

Errors encountered while generating Python bindings #33

@mattparks

Description

@mattparks

Based on feature/arm commit a46472c.
Tested on Ubuntu 20.04, clang-17, --std=20, libstdc++.

1. std::hash template specialization

#include <cstdint>
#include <functional>

namespace test {

struct Index {
    constexpr operator uint64_t() const noexcept {
        return 0U; /* Implementation detail */
    }
};

}  // namespace test

namespace std {

template<>
struct hash<test::Index> {
    size_t operator()(const test::Index index) const noexcept {
        return std::hash<uint64_t>()(index);
    }
};

}  // namespace std
[Tolc][error]: Failed to find template declaration for template specialization "std::hash<struct test::Index>". Did it appear before the specialization in the source?
[Tolc][error]: Error reported from Parser

2. Non-overloaded operator

#include <cstdint>

namespace test {

struct ID {
    constexpr operator uint64_t() const noexcept {
        return 0U; /* Implementation detail */
    }
};

}  // namespace test
[Tolc][error]: Unsupported operator "test::ID::operator unsigned long"
[Tolc][error]: Error reported from Parser

Note: binder supports a few extra operators, this has proven useful: https://github.com/RosettaCommons/binder/blob/master/source/function.cpp#L48

3. Templatized struct member variable

#include <random>

template <class I>
struct Demo {
    std::uniform_real_distribution<I> _distribution;
};
[Tolc][error]: Failed to parse member variable "Demo::_distribution"
[Tolc][error]: Error reported from Parser

4. Templatized struct function return type

template<class T = float>
struct unit {
    friend constexpr unit operator+(const unit lhs,
                                    const unit rhs) {
        return unit{lhs.val + rhs.val};
    }

    T val;
};
[Tolc][error]: Failed to parse return type "unit<T>" for function "operator+"
[Tolc][error]: Error reported from Parser

5. Portability concern

Building the tolc executable can be done from one machine, and binding executions could be done on a different machine with a difference in paths.
https://github.com/Tolc-Software/tolc/blob/feature/arm/src/Parser/Helpers/commandLineArgs.cpp#L13 using -nostdinc++ could cause issues.
Here's another instance of baked in system specific paths: https://github.com/Tolc-Software/tolc/blob/feature/arm/src/TolcInternal/getSystemIncludes.cpp.in#L25

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