Skip to content

Commit

Permalink
fix(cpp1): do not emit access specifier on x :== :() 0;
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Nov 17, 2023
1 parent 2892889 commit 884d180
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions regression-tests/pure2-type-and-namespace-aliases.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template<typename T> class myclass2;
class myclass3;


#line 49 "pure2-type-and-namespace-aliases.cpp2"
#line 50 "pure2-type-and-namespace-aliases.cpp2"
class myclass4;

template<typename T> class myclass6;
Expand Down Expand Up @@ -81,14 +81,15 @@ 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 {};

template<typename T> class myclass6 {
public: template<typename U>
CPP2_REQUIRES_ (true)
#line 52 "pure2-type-and-namespace-aliases.cpp2"
#line 53 "pure2-type-and-namespace-aliases.cpp2"
static constexpr auto v = 0;
};

Expand Down Expand Up @@ -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();


2 changes: 2 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,7 @@ struct declaration_node
// Cache some context
bool is_template_parameter = false;
bool is_parameter = false;
bool is_named = false;

// Constructor
//
Expand Down Expand Up @@ -7749,6 +7750,7 @@ class parser
-> std::unique_ptr<declaration_node>
{
auto n = std::make_unique<declaration_node>( current_declarations.back() );
n->is_named = named;
n->pos = start;

n->identifier = std::move(id);
Expand Down
5 changes: 4 additions & 1 deletion source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 884d180

Please sign in to comment.