Skip to content

Commit

Permalink
fix(cpp1): emit body of non local function expression (hsutter#601)
Browse files Browse the repository at this point in the history
* test: add unit test for non local function expressions

* fix(cpp1): emit body of non local function expression

* test: add missing result
  • Loading branch information
JohelEGP authored Sep 2, 2023
1 parent 8ade56b commit ce5bd83
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
v: <T> concept = :() -> bool = true;();

u: type == std::type_identity_t<decltype(:() = {})>;

t: @struct type = {
this: std::type_identity_t<decltype(:() = {})>;
}

main: () = { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#define CPP2_USE_MODULES Yes

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


#line 5 "pure2-bugfix-for-non-local-function-expression.cpp2"
class t;


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-bugfix-for-non-local-function-expression.cpp2"
template<typename T> concept v = []() -> bool { return true; }();

using u = std::type_identity_t<decltype([]() -> void{})>;

class t: public std::type_identity_t<decltype([]() -> void{})> {

};

auto main() -> int;


//=== Cpp2 function definitions =================================================


#line 9 "pure2-bugfix-for-non-local-function-expression.cpp2"
auto main() -> int{}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-bugfix-for-non-local-function-expression.cpp2... ok (all Cpp2, passes safety checks)

5 changes: 4 additions & 1 deletion source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5671,7 +5671,10 @@ class cppfront
}

// If we're only emitting declarations, end the function declaration
if (printer.get_phase() == printer.phase1_type_defs_func_decls)
if (
printer.get_phase() == printer.phase1_type_defs_func_decls
&& !n.is_function_expression()
)
{
emit_requires_clause();
printer.print_cpp2( ";\n", n.position() );
Expand Down
3 changes: 3 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,9 @@ struct declaration_node
auto is_alias() const -> bool
{ return type.index() == an_alias; }

auto is_function_expression () const -> bool
{ return is_function() && !identifier; }

auto is_polymorphic() const // has base types or virtual functions
-> bool
{
Expand Down

0 comments on commit ce5bd83

Please sign in to comment.