@print
Title: Single-expression functions print with extra semicolon.
Description:
This makes the printed code invalid Cpp2:
example.cpp2(4,51): error: a single-expression function should end with a single semicolon (at ';')
Minimal reproducer (https://cpp2.godbolt.org/z/jGb31dK74):
#include <functional> t: @struct @print type = { x: std::function<void()> = :() = _ = 0; y: std::function<void()> = :() 0; } main: () = { }
cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result: Printed Cpp2 code to be valid.
Actual result and error: public x: std::function<void()> = :() = _ = 0;;.
public x: std::function<void()> = :() = _ = 0;;
//=== Cpp2 type declarations ==================================================== #include "cpp2util.h" class t; //=== Cpp2 type definitions and function declarations =========================== #include <functional> class t { public: std::function<void()> x {[]() -> void { static_cast<void>(0); }}; public: std::function<void()> y {[]() -> auto { return 0; }}; }; auto main() -> int; //=== Cpp2 function definitions ================================================= auto main() -> int{}
main.cpp2... t: type = { public x: std::function<void()> = :() = _ = 0;; public y: std::function<void()> = :() -> move _ = 0;; } ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)
See also:
Very sorry for the questions but what does print metafunction do? Also, is it confirmed that multiple metafunctions can be applied on the same type?
print
Thanks for the answer!
Thanks!
I think I got them all, including the ones in your test cases and a few more... but please check and reopen with a new test case if I missed some.
@struct doesn't generate Cpp2 code, but instead affects lowering. So it should be @printed.
@struct
Good point, that's the simplest fix for now so I'll implement it that way. Thanks!
Make pretty-print include `@struct` if present, updates #840
Make pretty-print emit metafunctions as comment, updates #840
Make pretty printing not emit double `;`, closes hsutter#840
Activity
[-][BUG] Single-expression functions print with extra semicolon[/-][+][BUG] `@print` shortcomings[/+]AbhinavK00 commentedon Nov 18, 2023
Very sorry for the questions but what does
printmetafunction do? Also, is it confirmed that multiple metafunctions can be applied on the same type?AbhinavK00 commentedon Nov 18, 2023
Thanks for the answer!
hsutter commentedon Dec 26, 2023
Thanks!
I think I got them all, including the ones in your test cases and a few more... but please check and reopen with a new test case if I missed some.
hsutter commentedon Dec 29, 2023
Good point, that's the simplest fix for now so I'll implement it that way. Thanks!
Make pretty-print include `@struct` if present, updates #840
Make pretty-print emit metafunctions as comment, updates #840
Make pretty printing not emit double `;`, closes hsutter#840