-
Notifications
You must be signed in to change notification settings - Fork 249
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] Cannot specity <const>
or <in>
in function template arguments
#456
Comments
<const>
or <in>
<const>
or <in>
in function template arguments
I think it may be a bug in the parser. //G template-argument-list:
//G template-argument-list ',' template-argument
//G
//G template-argument:
//G # note: < > << >> are not allowed in expressions until new ( is opened
//G expression
//G type-id Or maybe it parses |
Some Questions: One more thing, I think it works with pointers because cpp2 thinks it's a pointer that doesn't change an object instead of a pointer that can't be reseated. Does that make sense? |
See #425 (comment).
That's the other side of #456 (comment). |
Ouch. |
I don't think so, as #425(comment) points out, a parameter direction does NOT operate on a type. And when you think about it,
do not make sense. So we need not to change the types in templates to atleast. |
OK I got where my misunderstanding about
That means some places use new syntax, some old, and thus Hence I found workaround for my issue
print nonconst, const, nonconst. Regarding |
That's because they're orthogonal features, You can declare a You can declare a parameter as being You can declare a return type to be by (some of) those. You can |
I also learnt the same thing from this issue, I had fully forgotten about |
auto main() -> int{
int* const x {g};
v<const * int>;
} One way to fix this is to introduce alternative grammars that are definitely not something else. +//G unqualified-type-id:
+//G id-expression
+//G function-type
+//G definite-type-id:
+//G type-qualifier-seq unqualified-type-id
+//G definite-function-type
//G type-id:
-//G type-qualifier-seq? id-expression
-//G type-qualifier-seq? function-type
+//G type-qualifier-seq? unqualified-type-id
//G template-argument:
//G # note: < > << >> are not allowed in expressions until new ( is opened
+//G definite-type-id
//G expression
//G type-id
+//G definite-parameter-declaration:
+//G parameter-direction unnamed-declaration
+//G this-specifier? parameter-direction? declaration
+//G this-specifier parameter-direction? identifier
//G parameter-declaration:
//G parameter-direction? unnamed-declaration
//G this-specifier? parameter-direction? declaration
//G this-specifier? parameter-direction? identifier
+//G definite-parameter-declaration-list
+//G '(' definite-parameter-declaration-seq ')'
+//G definite-parameter-declaration-seq:
+//G definite-parameter-declaration
+//G definite-parameter-declaration-seq ',' definite-parameter-declaration
+//G definite-function-type:
+//G definite-parameter-declaration-list throws-specifier? return-list?
//G function-type:
//G parameter-declaration-list throws-specifier? return-list? contract-seq?
//G return-list:
//G '->' type-id And similarly for #387 (comment): +//G inconclusive-parameter-declaration:
+//G unnamed-declaration
+//G parameter-direction identifier
+//G identifier
+//G inconclusive-parameter-declaration-list:
+//G inconclusive-parameter-declaration
+//G inconclusive-parameter-declaration-list ',' inconclusive-parameter-declaration
+//G inconclusive-type-id:
+//G '(' inconclusive-parameter-declaration-list ')'
//G is-as-expression:
//G prefix-expression
+//G is-as-expression is-definite-value-constraint
//G is-as-expression is-type-constraint
//G is-as-expression is-value-constraint
//G is-as-expression as-type-cast
//GTODO type-id is-type-constraint
+//G is-definite-value-constraint
+//G 'is' inconclusive-type-id |
The suggested complication above The alternatives I've considered are (assuming no function type support):
|
Here's a simpler alternative, with support for function types. Proposal parameter-declaration-list achieves feature parity with Cpp1. The alternative maintains the status-quo: Parameters of a declaration can't be unnamed. First, define function-type-id: //G type-id:
//G type-qualifier-seq? id-expression
+//G type-qualifier-seq? function-type-id
//G parameter-declaration:
//G this-specifier? parameter-direction? declaration
//G this-specifier? parameter-direction? identifier
+//G parameter-declaration-type:
+//G parameter-direction? unnamed-declaration
//G parameter-declaration-list
//G '(' parameter-declaration-seq? ')'
+//G parameter-declaration-type-list
+//G '(' parameter-declaration-type-seq? ')'
//G parameter-declaration-seq:
//G parameter-declaration
//G parameter-declaration-seq ',' parameter-declaration
+//G parameter-declaration-type-seq:
+//G parameter-declaration-type
+//G parameter-declaration-type-seq ',' parameter-declaration-type
//G function-type:
//G parameter-declaration-list throws-specifier? return-list? contract-seq?
+//G function-type-id:
+//G parameter-declaration-type-list throws-specifier? return-list? Then, to fix this issue (#456), update template-argument: //G template-argument:
//G # note: < > << >> are not allowed in expressions until new ( is opened
+//G 'const' type-id
+//G function-type-id
//G expression
//G type-id With that:
And to workaround #387 (comment):
|
Or maybe just add function-type-id as a synonym for function-type, //G type-id:
//G type-qualifier-seq? id-expression
+//G type-qualifier-seq? function-type-id
//G function-type:
//G parameter-declaration-list throws-specifier? return-list? contract-seq?
+//G function-type-id:
+//G # Note: Parameters must match `parameter-direction? unnamed-declaration`.
+//G function-type
//G template-argument:
//G # note: < > << >> are not allowed in expressions until new ( is opened
+//G 'const' type-id
+//G function-type-id
//G expression
//G type-id |
Let's assume that |
After some thinking and recalling some of Herb's comments, So if Cpp2 |
For #492 (comment), I wrote
I take advantage of We've already mentioned But wanting to specify reference types for template arguments
|
Although |
I think in one talk Herb metioned also, that he would like to introduce specifications on the calling side like
If this is introduced, then it would only be logical that template parameters could also be specified in with these modifiers without using |
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
https://cpp2.godbolt.org/z/sjMWTq3b7
But according to this comment #425 (comment) , it works on pointers
https://cpp2.godbolt.org/z/Tx8e9KfKc
f<* const int>();
The text was updated successfully, but these errors were encountered: