-
Notifications
You must be signed in to change notification settings - Fork 260
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
feat: support function types #526
Conversation
1a764db
to
a9a6a88
Compare
a9a6a88
to
0c82d8e
Compare
0c82d8e
to
2649d72
Compare
source/cppfront.cpp
Outdated
@@ -5783,7 +5895,7 @@ class cppfront | |||
} | |||
} | |||
printer.preempt_position_push(n.position()); | |||
emit( *type ); | |||
emit( *type, false, true ); | |||
printer.preempt_position_pop(); | |||
// one pointer is enough for now, pointer-to-function fun can be later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this about?
Is it an outdated comment now?
2649d72
to
1e9b9cd
Compare
1e9b9cd
to
44a357b
Compare
Title: Observable difference in template function's type. Description: This is due to the fact that Minimal reproducer:
Commands:cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp Expected result: I'm not sure. Attempting to extent the exception in the description can only get you so far. Actual result and error: Cpp2 lowered to Cpp1:#define CPP2_USE_MODULES Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-function-type-id.cpp2"
template<typename T> auto f(T const& x) -> void;
auto main() -> int;
//=== Cpp2 function definitions =================================================
#line 1 "pure2-function-type-id.cpp2"
template<typename T> auto f(T const& x) -> void{cpp2::fn_t<void(cpp2::in<T>)>* g {f}; }
auto main() -> int{(void) f(cpp2::i32{0});}
|
LGTM. In your current commits, there are always some white-space fixes. These clutter the commit a little bit. Maybe we can have a pull request, that fixes all the white-spaces once and for all. |
Thanks for the hint, I did not know that this can be enabled in the github view. |
Add _function-type_ as an alternative production of _type-id_. A parameter's identifier must be named `_`. `!throws` needs to be specified for Cpp1-`noexcept` function types. Some examples: ```Cpp2 main: () = { f0: * () = :() = {}; f7: * (move _: i32) = :(move x: i32) = {}; [[assert: inspect f0 -> bool { is () !throws = (std::terminate(), false); is * () = true; is _ = false; }]] } // Test case from hsutter#343. f2: () -> std::function<(_: std::string) -> std::string> = { return :(s: std::string) -> std::string = { return s + " World!"; }; } // Adapted from <https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-operators>. f: (x: i32) -> * (_: i32) -> std::string = :(x: i32) -> std::string = ""; postfix_operators: () = { [[assert: f is (_: i32) -> * (_: i32) -> std::string]] // / | | // / | | [[assert: f(42) is * (_: i32) -> std::string]] // _________/ | // / | [[assert: f(42)* is (_: i32) -> std::string]] // ________/ // / [[assert: (f(42)*)(1) is std::string]] }
`error C3537: you cannot cast to a type that contains 'auto'`. See <https://compiler-explorer.com/z/Tfbj795s3> not working and <https://compiler-explorer.com/z/31osnhrGo> working.
768c5d3
to
6e88091
Compare
Hand-merged #526 into current main code Some basic examples compile, but `reflect.h2` doesn't yet, needs investigation I've commented out some error message emission on what appeared to be trial parses(?), because the presence of the error message stopped further processing
Thanks again for this good PR, and deep apologies for the delay as I haven't kept up with PRs. Because |
…in <> lists (#1183) * Starting over on function types - initial support for function types in <> lists Should generally support std::function<> style uses Aside: I'm happy to find that C++ allows parameter names in function types, thank you WG21! I hadn't seen those used in examples so I had been expecting that cppfront would have to suppress those, but std::function< int ( std::string& param_name ) > is legal code. Sweet. This commit does not yet support pointer-to-function local variables... * Add support for pointer-to-function variables * Add docs examples for function typeids with std::function & *pfn * Add support for pointer to function parameter types * Support function type ids in type aliases
Resolves #525.
Resolves #502.
Resolves #343. Resolves #711. Resolves #718.
Partially addresses #387 (parameter-declaration-list).
Testing summary:
Acknowledgements: