-
Notifications
You must be signed in to change notification settings - Fork 252
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] Add support for defining template specializations. #467
Comments
The diamonds come after the metafunctions. Some more examples:
Another thing to consider is how a nested namespace definition will be supported
The current grammar has identifiers before a declaration's colon only:
Supporting the specialization of templates The expressions, unfortunately, complicate parsing.
|
@JohelEGP Unrelated, but how will this code be compiled?
Because
is invalid Cpp1. |
That was my mistake. It should have been this:
|
Just an idea: Directly specifying the specialized template arguments in the declaration name comes from the current cpp1 syntax. In cpp2 syntax this could be moved nearly anywhere else. So a few examples:
I think 1. would have problems with the specialization of function templates. My preference would be 2. |
I think the original expected syntax is consistent with Cpp2's way of "declaration follows use".
Originally, this is what I was going to suggest.
|
I think in this example the declaration follows use would be broken. In
we would follow the left to right principle: For a function it would look like:
|
IIUC, it seems like it comes down to choosing tradeoffs. Another thing to consider when choosing the syntax
|
I like this, and will try to implement it. //G template-specialization-argument-list:
//G '<' template-argument-list? '>'
//G
//G unnamed-declaration:
//G ':' meta-functions-list? template-parameter-declaration-list? function-type requires-clause? '=' statement
//G ':' meta-functions-list? template-parameter-declaration-list? template-specialization-argument-list? type-id? requires-clause? '=' statement
//G ':' meta-functions-list? template-parameter-declaration-list? type-id
//G ':' meta-functions-list? template-parameter-declaration-list? template-specialization-argument-list? 'final'? 'type' requires-clause? '=' statement
//G ':' 'namespace' '=' statement |
I'm going with the Solved in the PRThere's an unsolvable ambiguity at the grammar level.
|
If the obvious syntax is problematic,
+//G specialization-declaration:
+//G template-parameter-declaration-list ':' unnamed-declaration
+//G template-parameter-declaration-list ':' alias
//G
//G unnamed-declaration:
//G ':' meta-functions-list? template-parameter-declaration-list? function-type requires-clause? '=' statement
//G ':' meta-functions-list? template-parameter-declaration-list? function-type statement
//G ':' meta-functions-list? template-parameter-declaration-list? type-id? requires-clause? '=' statement
//G ':' meta-functions-list? template-parameter-declaration-list? type-id
//G ':' meta-functions-list? template-parameter-declaration-list? 'final'? 'type' requires-clause? '=' statement
+//G ':' specialization-declaration
//G ':' 'namespace' '=' statement
//G
//G alias:
//G ':' template-parameter-declaration-list? 'type' requires-clause? '==' type-id ';'
//G ':' 'namespace' '==' id-expression ';'
//G ':' template-parameter-declaration-list? type-id? requires-clause? '==' expression ';'
+//G ':' specialization-declaration Or: //G declaration:
//G access-specifier? identifier '...'? unnamed-declaration
//G access-specifier? identifier alias
+//G access-specifier? identifier '...'? specialization-declaration |
As with past issues, the only problem with the "obvious" syntax is that it doesn't work in the global namespace.
This will mostly come up in tests or slide code, where it's usual to not have namespaces. |
AFAIK, there's no way to define template specializations in cppfront. I found this out when trying to define a custom
std::formatter
.Here's my expected syntax.
As of now, cppfront doesn't attempt to compile the
std::formatter<Foo>
part.https://godbolt.org/z/eKd8Y9aWz
The text was updated successfully, but these errors were encountered: