cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] Concept is generated in type definition section while needed in type declaration section

Open MetaZ9 opened this issue 9 months ago • 1 comments

Describe the bug Pretty self-explanatory. Concepts are generated in the type definition section of a generated file (header or source file); but a template class with said concept will be declared in the type declaration section, before the concept is defined, resulting in an error later.

To Reproduce

import <type_traits>;

Foo: @interface type = {}

FooType: <T> concept = std::is_base_of_v<Foo, T>;

Bar: <T: FooType> type = {}

Generated code :

class Foo;

template<FooType T> class Bar; //FooType needed here

import <type_traits>;

class Foo {/* ... */};

template<typename T> concept FooType = std::is_base_of_v<Foo,T>; //FooType only declared here

template<FooType T> class Bar {/* ... */};

Discussion Since concepts can be used as part of a class declaration, I think they should be placed in the declaration section, even if it's essentially a definition. That said, I'm not sure it's trivial and I don't know all the implications. I'm not fully familiar with concepts, but it seems to me that you can do quite complex things in concept definitions, perhaps some need more than a simple type declaration to be compiled.

MetaZ9 avatar Apr 18 '25 15:04 MetaZ9