From 884d180a8562a213eaed9059e7e29cc8d70d1726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Fri, 17 Nov 2023 16:11:32 -0400 Subject: [PATCH] fix(cpp1): do not emit access specifier on `x :== :() 0;` --- regression-tests/pure2-type-and-namespace-aliases.cpp2 | 1 + .../test-results/pure2-type-and-namespace-aliases.cpp | 6 ++++-- source/parse.h | 2 ++ source/to_cpp1.h | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/regression-tests/pure2-type-and-namespace-aliases.cpp2 b/regression-tests/pure2-type-and-namespace-aliases.cpp2 index 0f6663df41..adf713394b 100644 --- a/regression-tests/pure2-type-and-namespace-aliases.cpp2 +++ b/regression-tests/pure2-type-and-namespace-aliases.cpp2 @@ -44,6 +44,7 @@ myclass3: @struct type = { v4: myclass3 == v2; // OK: Doesn't use the Cpp2 placeholder type. v5: myclass4 == myclass4(); // OK: Doesn't use the Cpp2 placeholder type. v6: myclass5 == myclass5(); // OK: Doesn't use the Cpp2 placeholder type. + v7 :== :() 0; } myclass4: @struct type = { } diff --git a/regression-tests/test-results/pure2-type-and-namespace-aliases.cpp b/regression-tests/test-results/pure2-type-and-namespace-aliases.cpp index 53c1f3cf52..85990aee55 100644 --- a/regression-tests/test-results/pure2-type-and-namespace-aliases.cpp +++ b/regression-tests/test-results/pure2-type-and-namespace-aliases.cpp @@ -24,7 +24,7 @@ template class myclass2; class myclass3; -#line 49 "pure2-type-and-namespace-aliases.cpp2" +#line 50 "pure2-type-and-namespace-aliases.cpp2" class myclass4; template class myclass6; @@ -81,6 +81,7 @@ class myclass3 { public: static const myclass3 v4;// OK: Doesn't use the Cpp2 placeholder type. public: static const myclass4 v5;// OK: Doesn't use the Cpp2 placeholder type. public: static const myclass5 v6;// OK: Doesn't use the Cpp2 placeholder type. + public: static constexpr auto v7 = []() -> auto { return 0; }; }; class myclass4 {}; @@ -88,7 +89,7 @@ class myclass4 {}; template class myclass6 { public: template CPP2_REQUIRES_ (true) -#line 52 "pure2-type-and-namespace-aliases.cpp2" +#line 53 "pure2-type-and-namespace-aliases.cpp2" static constexpr auto v = 0; }; @@ -132,4 +133,5 @@ auto main() -> int{ inline CPP2_CONSTEXPR myclass3 myclass3::v4 = v2; inline CPP2_CONSTEXPR myclass4 myclass3::v5 = myclass4(); inline CPP2_CONSTEXPR myclass5 myclass3::v6 = myclass5(); + diff --git a/source/parse.h b/source/parse.h index 1215f15593..c9e1a3ddd2 100644 --- a/source/parse.h +++ b/source/parse.h @@ -2554,6 +2554,7 @@ struct declaration_node // Cache some context bool is_template_parameter = false; bool is_parameter = false; + bool is_named = false; // Constructor // @@ -7749,6 +7750,7 @@ class parser -> std::unique_ptr { auto n = std::make_unique( current_declarations.back() ); + n->is_named = named; n->pos = start; n->identifier = std::move(id); diff --git a/source/to_cpp1.h b/source/to_cpp1.h index 31806b746a..9dabe7f8cc 100644 --- a/source/to_cpp1.h +++ b/source/to_cpp1.h @@ -5363,7 +5363,10 @@ class cppfront // In class definitions, emit the explicit access specifier if there // is one, or default to private for data and public for functions - if (printer.get_phase() == printer.phase1_type_defs_func_decls) + if ( + printer.get_phase() == printer.phase1_type_defs_func_decls + && n.is_named + ) { if (!n.is_default_access()) { assert (is_in_type);