Skip to content

Commit

Permalink
Start roughing in statement and compound_statement
Browse files Browse the repository at this point in the history
Usability: Don't make multi-argument constructors explicit
  • Loading branch information
hsutter committed Nov 3, 2024
1 parent 36ccbf9 commit 9901b01
Show file tree
Hide file tree
Showing 20 changed files with 767 additions and 555 deletions.
6 changes: 3 additions & 3 deletions include/cpp2regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ template<typename CharT, typename Iter, int max_groups> class match_context

private: std::array<match_group<Iter>,max_groups> groups {};

public: explicit match_context(Iter const& begin_, Iter const& end_);
public: match_context(Iter const& begin_, Iter const& end_);

#line 68 "cpp2regex.h2"
public: match_context(match_context const& that);
Expand Down Expand Up @@ -212,7 +212,7 @@ template<typename Func> class on_return
{
private: Func func;

public: explicit on_return(Func const& f);
public: on_return(Func const& f);
#line 136 "cpp2regex.h2"
public: auto operator=(Func const& f) -> on_return& ;

Expand Down Expand Up @@ -577,7 +577,7 @@ template<typename CharT, typename matcher_wrapper> class regular_expression
public: context<Iter> ctx;
public: int pos;

public: explicit search_return(cpp2::impl::in<bool> matched_, context<Iter> const& ctx_, Iter const& pos_);
public: search_return(cpp2::impl::in<bool> matched_, context<Iter> const& ctx_, Iter const& pos_);

#line 690 "cpp2regex.h2"
public: [[nodiscard]] auto group_number() const& -> decltype(auto);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:36: error: expected ‘;’ at end of member declaration
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:27: error: expected ‘;’ at end of member declaration
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
../../../include/cpp2util.h:10106:47: error: static assertion failed: GCC 11 or higher is required to support variables and type-scope functions that have a 'requires' clause. This includes a type-scope 'forward' parameter of non-wildcard type, such as 'func: (this, forward s: std::string)', which relies on being able to add a 'requires' clause - in that case, use 'forward s: _' instead if you need the result to compile with GCC 10.
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
Expand All @@ -8,7 +8,7 @@ In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cp
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:4:1: note: in expansion of macro ‘CPP2_REQUIRES_’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:112&&) requires is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type, const std::__cxx11::add_const_t<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&>’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:11: note: candidates are: ‘element::element(const element&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:110> element::element(auto:110&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:11: note: ‘template<class auto:110> element::element(auto:110&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:5:78: error: expected unqualified-id before ‘{’ token
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:8: error: no declaration matches ‘element& element::operator=(auto:113&&) requires is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(element::operator=::n)>::type>::type, const std::__cxx11::add_const_t<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&>’
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class quantity;
class quantity {
#line 2 "pure2-bugfix-for-discard-precedence.cpp2"
private: cpp2::i32 number;
public: explicit quantity(cpp2::impl::in<cpp2::i32> x);
public: quantity(cpp2::impl::in<cpp2::i32> x);
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
public: auto operator=(cpp2::impl::in<cpp2::i32> x) -> quantity& ;
public: [[nodiscard]] auto operator+(quantity const& that) & -> quantity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class element;
class element {
#line 2 "pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2"
private: std::string name;
public: explicit element(auto&& n)
public: element(auto&& n)
CPP2_REQUIRES_ (std::is_convertible_v<CPP2_TYPEOF(n), std::add_const_t<std::string>&>) ;
#line 3 "pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2"
public: auto operator=(auto&& n) -> element&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class widget final
{
private: int v;

public: explicit widget(cpp2::impl::in<int> value);
public: widget(cpp2::impl::in<int> value);
#line 6 "pure2-defaulted-comparisons-and-final-types.cpp2"
public: auto operator=(cpp2::impl::in<int> value) -> widget& ;

Expand Down
2 changes: 1 addition & 1 deletion regression-tests/test-results/pure2-last-use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class issue_857_9: public issue_857_8 {
};

class issue_869_0 {
public: explicit issue_869_0([[maybe_unused]] std::unique_ptr<int>&& unnamed_param_2);
public: issue_869_0([[maybe_unused]] std::unique_ptr<int>&& unnamed_param_2);
#line 366 "pure2-last-use.cpp2"
public: auto operator=([[maybe_unused]] std::unique_ptr<int>&& unnamed_param_2) -> issue_869_0& ;
public: [[nodiscard]] auto operator<=>([[maybe_unused]] issue_869_0 const& that) const& -> std::strong_ordering = default;
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/test-results/pure2-types-basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class myclass {
public: auto operator=(cpp2::impl::in<int> x) -> myclass& ;

#line 13 "pure2-types-basics.cpp2"
public: explicit myclass(cpp2::impl::in<std::string> s);
public: myclass(cpp2::impl::in<std::string> s);
#line 13 "pure2-types-basics.cpp2"
public: auto operator=(cpp2::impl::in<std::string> s) -> myclass& ;

#line 20 "pure2-types-basics.cpp2"
public: explicit myclass(cpp2::impl::in<int> x, cpp2::impl::in<std::string> s);
public: myclass(cpp2::impl::in<int> x, cpp2::impl::in<std::string> s);

#line 27 "pure2-types-basics.cpp2"
public: explicit myclass();
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/test-results/pure2-types-inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Human {

namespace N {
template<int I> class Machine {
public: explicit Machine([[maybe_unused]] cpp2::impl::in<std::string> unnamed_param_2);
public: Machine([[maybe_unused]] cpp2::impl::in<std::string> unnamed_param_2);
public: virtual auto work() const -> void = 0;
public: virtual ~Machine() noexcept;

Expand All @@ -58,7 +58,7 @@ struct Cyborg_address_as_base { std::string address; };
class Cyborg: public Cyborg_name_as_base, public Human, public Cyborg_address_as_base, public N::Machine<99> {

#line 19 "pure2-types-inheritance.cpp2"
public: explicit Cyborg(cpp2::impl::in<std::string> n);
public: Cyborg(cpp2::impl::in<std::string> n);

#line 25 "pure2-types-inheritance.cpp2"
public: auto speak() const -> void override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class X {
private: Y* py;

// Note: A constructor with an 'out' parameter
public: explicit X(cpp2::impl::out<Y> y);
public: X(cpp2::impl::out<Y> y);
#line 10 "pure2-types-order-independence-and-nesting.cpp2"
public: auto operator=(cpp2::impl::out<Y> y) -> X& ;

Expand All @@ -64,7 +64,7 @@ class X {
class Y {
private: X* px;

public: explicit Y(X* x);
public: Y(X* x);
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
public: auto operator=(X* x) -> Y& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class mystruct;
#line 2 "pure2-types-ordering-via-meta-functions.cpp2"
class my_integer {
private: int v;
public: explicit my_integer(cpp2::impl::in<int> val);
public: my_integer(cpp2::impl::in<int> val);
#line 4 "pure2-types-ordering-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<int> val) -> my_integer& ;
public: [[nodiscard]] auto operator<=>(my_integer const& that) const& -> std::strong_ordering = default;
Expand All @@ -44,7 +44,7 @@ class my_integer {

class case_insensitive_string {
private: std::string v; // case insensitive
public: explicit case_insensitive_string(cpp2::impl::in<std::string> val);
public: case_insensitive_string(cpp2::impl::in<std::string> val);
#line 9 "pure2-types-ordering-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<std::string> val) -> case_insensitive_string& ;
public: [[nodiscard]] auto operator<=>(case_insensitive_string const& that) const& -> std::weak_ordering = default;
Expand All @@ -57,7 +57,7 @@ class case_insensitive_string {

class person_in_family_tree {
private: int dummy_data;
public: explicit person_in_family_tree(cpp2::impl::in<int> parents);
public: person_in_family_tree(cpp2::impl::in<int> parents);
#line 14 "pure2-types-ordering-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<int> parents) -> person_in_family_tree& ;
public: [[nodiscard]] auto operator<=>(person_in_family_tree const& that) const& -> std::partial_ordering = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class myclass {
public: auto operator=(myclass&& that) noexcept -> myclass& ;

#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
public: explicit myclass(cpp2::impl::in<std::string> x);
public: myclass(cpp2::impl::in<std::string> x);
#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
public: auto operator=(cpp2::impl::in<std::string> x) -> myclass& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class myclass {
// std::cout << "assign - move ";
// }

public: explicit myclass(cpp2::impl::in<std::string> x);
public: myclass(cpp2::impl::in<std::string> x);
#line 22 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
public: auto operator=(cpp2::impl::in<std::string> x) -> myclass& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class myclass {
public: auto operator=(myclass&& that) noexcept -> myclass& ;

#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
public: explicit myclass(cpp2::impl::in<std::string> x);
public: myclass(cpp2::impl::in<std::string> x);
#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
public: auto operator=(cpp2::impl::in<std::string> x) -> myclass& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class myclass {
public: auto operator=(myclass&& that) noexcept -> myclass& ;

#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
public: explicit myclass(cpp2::impl::in<std::string> x);
public: myclass(cpp2::impl::in<std::string> x);
#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
public: auto operator=(cpp2::impl::in<std::string> x) -> myclass& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class myclass {
// std::cout << "assign - move ";
// }

public: explicit myclass(cpp2::impl::in<std::string> x);
public: myclass(cpp2::impl::in<std::string> x);
#line 22 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
public: auto operator=(cpp2::impl::in<std::string> x) -> myclass& ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class p_widget;
#line 2 "pure2-types-value-types-via-meta-functions.cpp2"
class widget {
private: int val {0};
public: explicit widget(cpp2::impl::in<int> i);
public: widget(cpp2::impl::in<int> i);
#line 4 "pure2-types-value-types-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<int> i) -> widget& ;
public: [[nodiscard]] auto operator<=>(widget const& that) const& -> std::strong_ordering = default;
Expand All @@ -43,7 +43,7 @@ public: explicit widget();

class w_widget {
private: int val {0};
public: explicit w_widget(cpp2::impl::in<int> i);
public: w_widget(cpp2::impl::in<int> i);
#line 9 "pure2-types-value-types-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<int> i) -> w_widget& ;
public: [[nodiscard]] auto operator<=>(w_widget const& that) const& -> std::weak_ordering = default;
Expand All @@ -59,7 +59,7 @@ public: explicit w_widget();

class p_widget {
private: int val {0};
public: explicit p_widget(cpp2::impl::in<int> i);
public: p_widget(cpp2::impl::in<int> i);
#line 14 "pure2-types-value-types-via-meta-functions.cpp2"
public: auto operator=(cpp2::impl::in<int> i) -> p_widget& ;
public: [[nodiscard]] auto operator<=>(p_widget const& that) const& -> std::partial_ordering = default;
Expand Down
10 changes: 10 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,16 @@ struct compound_statement_node

compound_statement_node(source_position o = source_position{});

auto get_statements()
-> std::vector<statement_node*>
{
auto ret = std::vector<statement_node*>{};
for (auto const& stmt : statements) {
ret.push_back( stmt.get() );
}
return ret;
}

auto position() const
-> source_position
{
Expand Down
Loading

0 comments on commit 9901b01

Please sign in to comment.