Skip to content

Commit

Permalink
Handle alias declaration before this base, closes #830
Browse files Browse the repository at this point in the history
And do a round of output formatting cleanup (high diffs)
  • Loading branch information
hsutter committed Nov 15, 2023
1 parent 11f2dbb commit 5ea5d5c
Show file tree
Hide file tree
Showing 105 changed files with 601 additions and 567 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:16:36: error: expected ‘;’ at end of member declaration
16 | public: explicit element(auto&& n)
| ^
| ;
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:36: error: expected ‘;’ at end of member declaration
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
../../../include/cpp2util.h:10005: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.cpp:17:1: note: in expansion of macro ‘CPP2_REQUIRES_’
17 | CPP2_REQUIRES_ (std::is_same_v<CPP2_TYPEOF(n), std::string>)
| ^~~~~~~~~~~~~~
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:46: error: expected ‘;’ at end of member declaration
In file included from pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:7:
../../../include/cpp2util.h:10005: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_’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: no declaration matches ‘element::element(auto:90&&) requires is_same_v<typename std::remove_cv<typename std::remove_reference<decltype(element::__ct ::n)>::type>::type, std::__cxx11::string>’
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.cpp:16:20: note: ‘template<class auto:88> element::element(auto:88&&)’
16 | public: explicit element(auto&& n)
| ^~~~~~~
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:14:7: note: ‘class element’ defined here
14 | class element {
| ^~~~~~~
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:3: error: expected unqualified-id before ‘{’ token
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:20: note: ‘template<class auto:88> element::element(auto:88&&)’
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:91&&) requires is_same_v<typename std::remove_cv<typename std::remove_reference<decltype(element::operator=::n)>::type>::type, std::__cxx11::string>’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:6:16: note: candidates are: ‘void element::operator=(const element&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:3:16: note: ‘template<class auto:89> element& element::operator=(auto:89&&)’
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp:14:7: note: ‘class element’ defined here
14 | class element {
| ^~~~~~~
pure2-bugfix-for-requires-clause-in-forward-declaration.cpp2:1:7: note: ‘class element’ defined here
4 changes: 2 additions & 2 deletions regression-tests/test-results/gcc-10/pure2-print.cpp.output
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ In file included from pure2-print.cpp:7:
pure2-print.cpp2:66:1: note: in expansion of macro ‘CPP2_REQUIRES_’
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
pure2-print.cpp2:94:1: note: in expansion of macro ‘CPP2_REQUIRES_’
pure2-print.cpp2:6:29: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
pure2-print.cpp2:6:36: error: template definition of non-template ‘constexpr const T outer::object_alias’
pure2-print.cpp2:7:41: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
pure2-print.cpp2:7:48: error: template definition of non-template ‘constexpr const T outer::object_alias’
pure2-print.cpp2:65:14: error: no declaration matches ‘void outer::mytype::variadic(const auto:97& ...) requires (is_convertible_v<typename std::remove_cv<typename std::remove_reference<decltype(outer::mytype::variadic::x)>::type>::type, int> && ...)’
pure2-print.cpp2:65:29: note: candidate is: ‘template<class ... auto:88> static void outer::mytype::variadic(const auto:88& ...)’
pure2-print.cpp2:8:19: note: ‘class outer::mytype’ defined here
Expand Down
2 changes: 2 additions & 0 deletions regression-tests/test-results/mixed-allcpp1-hello.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#line 1 "mixed-allcpp1-hello.cpp2"
#line 1 "mixed-allcpp1-hello.cpp2"

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

The first one of these is good, the second is redundant.


// Step 1: rename .cpp to .cpp2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@

#include "cpp2util.h"

#line 1 "mixed-as-for-variant-20-types.cpp2"

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

This addition does nothing, unless you are trying to associate the blank line following with the corresponding blank line in the original source file. That may or may not be useful. There are many of these.



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

#line 1 "mixed-as-for-variant-20-types.cpp2"
template<int I>
struct X { operator int() const { return I; } };

#line 4 "mixed-as-for-variant-20-types.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-as-for-variant-20-types.cpp2"

#line 4 "mixed-as-for-variant-20-types.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
4 changes: 3 additions & 1 deletion regression-tests/test-results/mixed-bounds-check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@

#include "cpp2util.h"

#line 1 "mixed-bounds-check.cpp2"


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

#line 1 "mixed-bounds-check.cpp2"

#include <vector>

#line 4 "mixed-bounds-check.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-bounds-check.cpp2"

#line 4 "mixed-bounds-check.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

#include "cpp2util.h"

#line 1 "mixed-bounds-safety-with-assert-2.cpp2"


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

#line 1 "mixed-bounds-safety-with-assert-2.cpp2"

#line 2 "mixed-bounds-safety-with-assert-2.cpp2"
[[nodiscard]] auto main() -> int;


#line 10 "mixed-bounds-safety-with-assert-2.cpp2"
auto add_42_to_subrange(auto& rng, cpp2::in<int> start, cpp2::in<int> end) -> void;
Expand All @@ -25,6 +26,7 @@ auto add_42_to_subrange(auto& rng, cpp2::in<int> start, cpp2::in<int> end) -> vo

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

#line 1 "mixed-bounds-safety-with-assert-2.cpp2"

#line 2 "mixed-bounds-safety-with-assert-2.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

#include "cpp2util.h"

#line 1 "mixed-bounds-safety-with-assert.cpp2"


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

#line 1 "mixed-bounds-safety-with-assert.cpp2"

#line 2 "mixed-bounds-safety-with-assert.cpp2"
[[nodiscard]] auto main() -> int;


#line 9 "mixed-bounds-safety-with-assert.cpp2"
auto print_subrange(auto const& rng, cpp2::in<int> start, cpp2::in<int> end) -> void;

#line 21 "mixed-bounds-safety-with-assert.cpp2"

#include <vector>
Expand All @@ -26,6 +26,7 @@ auto print_subrange(auto const& rng, cpp2::in<int> start, cpp2::in<int> end) ->

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

#line 1 "mixed-bounds-safety-with-assert.cpp2"

#line 2 "mixed-bounds-safety-with-assert.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

#include "cpp2util.h"

#line 1 "mixed-bugfix-for-cpp2-comment-cpp1-sequence.cpp2"

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

This line does not even associate a blank line with a blank line in the source, there is code on line 1.



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

#line 1 "mixed-bugfix-for-cpp2-comment-cpp1-sequence.cpp2"

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

This one is actually needed and wasn't there before, so that's good.

extern cpp2::i32 x;
int main() { }
// ugh

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

#line 1 "mixed-bugfix-for-cpp2-comment-cpp1-sequence.cpp2"
cpp2::i32 x {0};

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

#include "cpp2util.h"

#line 1 "mixed-bugfix-for-literal-as-nttp.cpp2"


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

#line 1 "mixed-bugfix-for-literal-as-nttp.cpp2"
#include <chrono>
using namespace std::chrono_literals;
#line 3 "mixed-bugfix-for-literal-as-nttp.cpp2"
auto main() -> int;


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

#line 1 "mixed-bugfix-for-literal-as-nttp.cpp2"

#line 3 "mixed-bugfix-for-literal-as-nttp.cpp2"
auto main() -> int{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@

#include "cpp2util.h"

#line 1 "mixed-captures-in-expressions-and-postconditions.cpp2"


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

#line 1 "mixed-captures-in-expressions-and-postconditions.cpp2"

#include <algorithm>
#include <vector>

#line 5 "mixed-captures-in-expressions-and-postconditions.cpp2"
[[nodiscard]] auto main() -> int;


#line 17 "mixed-captures-in-expressions-and-postconditions.cpp2"
extern std::vector<int> vec;

auto insert_at(cpp2::in<int> where, cpp2::in<int> val) -> void;


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

#line 1 "mixed-captures-in-expressions-and-postconditions.cpp2"

#line 5 "mixed-captures-in-expressions-and-postconditions.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
5 changes: 3 additions & 2 deletions regression-tests/test-results/mixed-fixed-type-aliases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

#include "cpp2util.h"

#line 1 "mixed-fixed-type-aliases.cpp2"

#line 15 "mixed-fixed-type-aliases.cpp2"
template<typename T> class mytype;


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

#line 1 "mixed-fixed-type-aliases.cpp2"
#include <filesystem>
#include <iostream>
#include <typeinfo>
Expand All @@ -22,18 +24,17 @@ namespace my {

#line 9 "mixed-fixed-type-aliases.cpp2"
auto test(auto const& x) -> void;


#line 15 "mixed-fixed-type-aliases.cpp2"
template<typename T> class mytype {
public: template<typename U> static const bool myvalue;
};

[[nodiscard]] auto main(int const argc_, char** argv_) -> int;


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

#line 1 "mixed-fixed-type-aliases.cpp2"

#line 9 "mixed-fixed-type-aliases.cpp2"
auto test(auto const& x) -> void{
Expand Down
5 changes: 3 additions & 2 deletions regression-tests/test-results/mixed-float-literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "cpp2util.h"

#line 1 "mixed-float-literals.cpp2"


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

#line 1 "mixed-float-literals.cpp2"
void literals_cpp1() {
// integers
std::cout << 123 << std::endl;
Expand Down Expand Up @@ -67,14 +69,13 @@ void literals_cpp1() {

#line 57 "mixed-float-literals.cpp2"
auto literals_cpp2() -> void;


#line 114 "mixed-float-literals.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-float-literals.cpp2"

#line 57 "mixed-float-literals.cpp2"
auto literals_cpp2() -> void{
Expand Down
24 changes: 9 additions & 15 deletions regression-tests/test-results/mixed-forwarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "cpp2util.h"

#line 1 "mixed-forwarding.cpp2"


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

#line 1 "mixed-forwarding.cpp2"
#include <iostream>
#include <utility>

Expand All @@ -26,24 +28,18 @@ auto use([[maybe_unused]] auto const& unnamed_param_1) -> void;

// invoking each of these with an rvalue std::pair argument ...
auto apply_implicit_forward(auto&& t) -> void
CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
#line 16 "mixed-forwarding.cpp2"
;

CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>) ;

#line 20 "mixed-forwarding.cpp2"
auto apply_explicit_forward(auto&& t) -> void
CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
#line 20 "mixed-forwarding.cpp2"
;

CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>) ;

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

This semicolon is now considered to be on line 21, which is the body of the function. I don't know that this would affect anything in practice, but it's a change from before this commit.


#line 25 "mixed-forwarding.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-forwarding.cpp2"

#line 11 "mixed-forwarding.cpp2"
auto copy_from([[maybe_unused]] auto unnamed_param_1) -> void{}
Expand All @@ -52,16 +48,14 @@ auto use([[maybe_unused]] auto const& unnamed_param_1) -> void{}

#line 16 "mixed-forwarding.cpp2"
auto apply_implicit_forward(auto&& t) -> void
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
#line 16 "mixed-forwarding.cpp2"
{
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>) {

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

The same as the semicolon above, this moves to a different line.

This comment has been minimized.

Copy link
@JohelEGP

JohelEGP Nov 15, 2023

Contributor

It's the same 17th line.
What actually changed comes after requires.
It looks like this because the { moved up.

This comment has been minimized.

Copy link
@gregmarr

gregmarr Nov 15, 2023

Contributor

Nope, previously it was on 16 because it's right after the #line 16 and now it's two lines after the #line 16 above. (I was referring to the {.)

#line 17 "mixed-forwarding.cpp2"
copy_from(t.first); // copies
copy_from(CPP2_FORWARD(t).second);// moves
}
auto apply_explicit_forward(auto&& t) -> void
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
#line 20 "mixed-forwarding.cpp2"
{
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>) {
#line 21 "mixed-forwarding.cpp2"
copy_from(CPP2_FORWARD(t).first);// moves
copy_from(CPP2_FORWARD(t).second);// moves
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "cpp2util.h"

#line 1 "mixed-function-expression-and-std-for-each.cpp2"


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

#line 1 "mixed-function-expression-and-std-for-each.cpp2"
#include <vector>
#include <string>
#include <span>
Expand All @@ -17,10 +19,10 @@

#line 7 "mixed-function-expression-and-std-for-each.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-function-expression-and-std-for-each.cpp2"

#line 7 "mixed-function-expression-and-std-for-each.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include "cpp2util.h"

#line 1 "mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2"


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

#line 1 "mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2"
#include <vector>
#include <ranges>
#include <string>
Expand All @@ -18,10 +20,10 @@

#line 8 "mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2"
[[nodiscard]] auto main() -> int;


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

#line 1 "mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2"

#line 8 "mixed-function-expression-and-std-ranges-for-each-with-capture.cpp2"
[[nodiscard]] auto main() -> int{
Expand Down
Loading

0 comments on commit 5ea5d5c

Please sign in to comment.