Skip to content

[BUG] @print shortcomings #840

Closed
Closed
@JohelEGP

Description

@JohelEGP

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: () = { }
Commands:
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;;.

Cpp2 lowered to Cpp1:
//=== 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{}
Output:
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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions