-
Notifications
You must be signed in to change notification settings - Fork 251
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
[SUGGESTION] Down with typename
!
#531
Comments
Note that because the Cpp2 grammar is unambiguous For example,
|
In Cpp2, the only grammar that could be an expression or type-id is a template-argument. Now, the C++ standard library isn't such a good example because it's not actual C++ code. |
First: I love the title just as much now as when I first saw Nina and Daveed use it :) Can you elaborate on what the proposal is though? Cpp2 currently doesn't use
The first line should not be allowed now, and the second is unambiguously a variable.
a) Currently b) Note that to test this you have to write the type in Cpp1, because I haven't yet provided a way to author static values in Cpp2. I probably will allow them, but require them to be Here's a working test program:
|
For this to work:
All those I'm actually working on a solution. #define CPP2_USE_MODULES Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "pure2-optional-typename.cpp2"
class t;
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-optional-typename.cpp2"
class t {
public: using type = cpp2::i32;
public: t() = default;
public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(t const&) -> void = delete;
#line 3 "pure2-optional-typename.cpp2"
};
template<typename T, typename T::type V> [[nodiscard]] auto f(cpp2::in<typename T::type> x) -> typename T::type;
[[nodiscard]] auto main() -> int;
//=== Cpp2 function definitions =================================================
#line 4 "pure2-optional-typename.cpp2"
template<typename T, typename T::type V> [[nodiscard]] auto f(cpp2::in<typename T::type> x) -> typename T::type { return typename T::type{x}; }
[[nodiscard]] auto main() -> int { return f<t,0>(0); }
|
This comment was marked as resolved.
This comment was marked as resolved.
There is a grammar where it's needed: template-argument. |
Would you be solving the ambiguity in template-argument the same as with is-as-expression? I think that would make sense, and be consistent.
If done, there might be one difference between template-argument and is-as-expression.
|
Ack: You beat me to it -- I've been out of computer range but was going to reply saying I expected it would be the same as I hope to finally be back in reliable computer range again on Friday... |
The same is true for an expression template argument that is lowered without the parentheses. However, that means that changing template-argument to consider type-id before expression |
Note that although #533 marks this PR as to-be-fixed by merging it, it doesn't implement this idea. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
First expressed at #529 (comment) (which occurred to me when working on that PR).
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code? 👌 (zero).
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
Assuming that Cpp2 supports
typename
for disambiguation, just like Cpp1.For a measure,
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2150r0.html#5.0
proposes to remove 254 uses of
typename
from the C++ standard library wording(extracted from the linked section's HTML by counting
<del>typename</del>
s).There's 765 occurrences of '
typename
' in the C++ standard library,not all disambiguating
typename
s(extracted from the library sources).
That's a 33% reduction.
Describe alternatives you've considered.
None.
There's nothing better than saying nothing at all when there's no room for another interpretation.
The text was updated successfully, but these errors were encountered: