robotpy/cxxheaderparser

[BUG]: Error for parsing user defined concepts

KevFri opened this issue · 2 comments

Problem description

#include <concepts>
#include <iostream>

namespace concepts {
template <typename TypeA, typename TypeB>
concept my_concept = requires {
  requires std::is_floating_point_v<TypeA>;
  requires std::is_integral_v<TypeB>;
};
} // namespace concepts

template <typename TypeA, typename TypeB>   //
requires concepts::my_concept<TypeA, TypeB> //
struct A {
  void foo() {
    std::cout << typeid(TypeA).name() << " " << typeid(TypeB).name()
              << std::endl;
  }
};

Output:
:14: parse error evaluating 'struct': unexpected 'struct', expected ',' or ';'

Operating System

Linux

Installed Python Packages

used this online parser: https://robotpy.github.io/cxxheaderparser/

Reproducible example code

#include <concepts>
#include <iostream>

namespace concepts {
template <typename TypeA, typename TypeB>
concept my_concept = requires {
  requires std::is_floating_point_v<TypeA>;
  requires std::is_integral_v<TypeB>;
};
} // namespace concepts

template <typename TypeA, typename TypeB>   //
requires concepts::my_concept<TypeA, TypeB> //
struct A {
  void foo() {
    std::cout << typeid(TypeA).name() << " " << typeid(TypeB).name()
              << std::endl;
  }
};

Thanks for the bug report. Interestingly, if you comment out the bottom section, it parses... but definitely not in any kind of sane way. Adding support for parsing requires should be pretty straightforward... (Note to self: concepts syntax is here: https://en.cppreference.com/w/cpp/language/constraints)

I'm taking vacation for a month starting next week, so the odds of me getting to this anytime soon are very low. I am very interested in fixing these issues this summer however.

#80 adds support to consume headers that contain concepts/requires in them. However, they aren't stored in any kind of sensible way (similar to decltype) because that would require a proper expression parser and that sounds hard.