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

[BUG] Parameter direction for template parameter is ignored #425

Closed
JohelEGP opened this issue May 6, 2023 · 5 comments
Closed

[BUG] Parameter direction for template parameter is ignored #425

JohelEGP opened this issue May 6, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented May 6, 2023

Title: Parameter direction for template parameter is ignored.

Minimal reproducer (https://cpp2.godbolt.org/z/M1jxGdeqe):

a: <in T> type = { }
b: <in V: _> type = { }
main: () = { }

Commands:

cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++2b -stdlib=libc++ -lc++abi -I . main.cpp

Expected result:

For the : type case, a diagnostic.
For the : _ case, adherence to the specified parameter direction.

template<typename T> class a; // A Cpp2 diagnostic here.
template<const auto& V> class b;

Actual result and error:

template<typename T> class a;
template<auto V> class b;
Program returned: 0
Cpp2 lowered to Cpp1.
#include "cpp2util.h"

template<typename T> class a;
template<auto V> class b;

template<typename T> class a {
      public: a() = default;
      public: a(a const&) = delete; /* No 'that' constructor, suppress copy */
      public: auto operator=(a const&) -> void = delete;

};
template<auto V> class b {
      public: b() = default;
      public: b(b const&) = delete; /* No 'that' constructor, suppress copy */
      public: auto operator=(b const&) -> void = delete;

};
auto main() -> int;

auto main() -> int{}
@JohelEGP JohelEGP added the bug Something isn't working label May 6, 2023
@realgdman
Copy link

Possibly related: I'm using library (flecs) with API like

ecs.system<Position, const Velocity>()
    .each([] some lambda

And haven't found way to specify that const in template call to system()
Which, I believe, cannot be deduced from parameters of lambda

	foo<int>();
	foo<const int>(); //error
	foo<int const>(); //error
	foo<in int>(); //error

https://cpp2.godbolt.org/z/sjMWTq3b7

@JohelEGP
Copy link
Contributor Author

Seems like a bug: https://cpp2.godbolt.org/z/Tx8e9KfKc.
I suggest you open a new issue, since this one is about template parameters, not template arguments.

@realgdman
Copy link

Ok, I do later, what I mean by related is, should I be able to put in in <> in that case.

@JohelEGP
Copy link
Contributor Author

I don't think that can work.
In a subexpression, a parameter direction operates on an expression, not a type.
cppfront doesn't have enough semantic information for f<in int>() to work.

@hsutter
Copy link
Owner

hsutter commented Aug 13, 2023

Parameter direction for template parameter is ignored.

Yes, this is by design -- I don't know what it would mean.

I should probably emit a diagnostic for it though. Thanks!

JohelEGP referenced this issue Nov 8, 2023
From `[[kind group: expression]]`

to `kind<group>(expression)`

Sorry for the breaking change to anyone who has been writing contacts. I'm trying to support gaining usage experience with P2961

Reference link: https://wg21.link/p2961r1
zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants