Skip to content

Commit c805166

Browse files
committed
Remove uses of __ that would be visible to Cpp1
I used `__` (double underscore) in some names on the grounds that I considered cppfront part of the implementation, but it's not part of the ISO C++ implementation and it's just barely possible that some of the uses could conflict with some implementation macro, so let's just avoid it for compatibility's sake Also take out `enum` streaming for now while I work further on friend lowering
1 parent fa9ba7f commit c805166

34 files changed

+222
-202
lines changed

include/cpp2util.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// #include'd by generated Cpp1 code
1818
//===========================================================================
1919

20-
#ifndef __CPP2_UTIL
21-
#define __CPP2_UTIL
20+
#ifndef CPP2_UTIL_H
21+
#define CPP2_UTIL_H
2222

2323
// If this implementation doesn't support source_location yet, disable it
2424
// TODO: technically this test should have <version> included first, but GEFN
@@ -241,6 +241,14 @@
241241
// these redundant goto's to avoid 'unused label' warnings
242242

243243

244+
#if defined(_MSC_VER)
245+
// MSVC can't handle 'inline constexpr' yet in all cases
246+
#define CPP2_CONSTEXPR const
247+
#else
248+
#define CPP2_CONSTEXPR constexpr
249+
#endif
250+
251+
244252
namespace cpp2 {
245253

246254

@@ -265,18 +273,18 @@ using u32 = std::uint32_t ;
265273
using u64 = std::uint64_t ;
266274

267275
// Discouraged: Variable precision names
268-
// short
269-
using ushort = unsigned short;
270-
// int
271-
using ulong = unsigned long;
272-
// long
273-
using longlong = long long;
274-
using ulonglong = unsigned long long;
276+
// short
277+
using ushort = unsigned short;
278+
// int
279+
using ulong = unsigned long;
280+
// long
281+
using longlong = long long;
282+
using ulonglong = unsigned long long;
275283
using longdouble = long double;
276284

277285
// Strongly discouraged, for compatibility/interop only
278-
using __schar = signed char; // normally use i8 instead
279-
using __uchar = unsigned char; // normally use u8 instead
286+
using _schar = signed char; // normally use i8 instead
287+
using _uchar = unsigned char; // normally use u8 instead
280288

281289

282290
//-----------------------------------------------------------------------

regression-tests/pure2-enum.cpp2

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ main: () = {
4141

4242
std::cout << "x.to_string() is (x.to_string())$\n";
4343
std::cout << "x2.to_string() is (x2.to_string())$\n";
44-
std::cout << "using << prints " << x << "\n";
4544

4645
std::cout << "with if else: ";
4746
if x == skat_game::diamonds { // ok, can compare two skat_games
@@ -85,13 +84,13 @@ main: () = {
8584
f2 := file_attributes::cached;
8685
std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
8786

88-
std::cout << "f is " << f << "\n";
89-
std::cout << "f2 is " << f2 << "\n";
87+
std::cout << "f is " << f.to_string() << "\n";
88+
std::cout << "f2 is " << f2.to_string() << "\n";
9089

9190
f2.clear( f2 );
92-
std::cout << "f2 is " << f2 << "\n";
91+
std::cout << "f2 is " << f2.to_string() << "\n";
9392
f2.set(file_attributes::cached);
94-
std::cout << "f2 is " << f2 << "\n";
93+
std::cout << "f2 is " << f2.to_string() << "\n";
9594

9695
std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
9796
std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
@@ -104,8 +103,8 @@ main: () = {
104103
f |= file_attributes::obsolete;
105104
f2 |= file_attributes::current;
106105

107-
std::cout << "f is " << f << "\n";
108-
std::cout << "f2 is " << f2 << "\n";
106+
std::cout << "f is " << f.to_string() << "\n";
107+
std::cout << "f2 is " << f2.to_string() << "\n";
109108
std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
110109
std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
111110
std::cout << "f == f2 is (f == f2 )$\n";

regression-tests/test-results/clang-12/pure2-enum.cpp.execution

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
x.to_string() is clubs
22
x2.to_string() is clubs
3-
using << prints clubs
43
with if else: clubs
54
with inspect: clubs
65

regression-tests/test-results/clang-12/pure2-print.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pure2-print.cpp2:52:80: warning: unused parameter 't' [-Wunused-parameter]
2-
template<typename T> [[nodiscard]] auto outer::mytype::values(T const& t) const& -> values__ret{
2+
template<typename T> [[nodiscard]] auto outer::mytype::values(T const& t) const& -> values_ret{
33
^
44
pure2-print.cpp2:63:53: warning: unused parameter 'x' [-Wunused-parameter]
55
auto outer::mytype::variadic(auto const& ...x) -> void{}

regression-tests/test-results/gcc-10/pure2-enum.cpp.execution

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
x.to_string() is clubs
22
x2.to_string() is clubs
3-
using << prints clubs
43
with if else: clubs
54
with inspect: clubs
65

regression-tests/test-results/gcc-10/pure2-print.cpp.output

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ In file included from pure2-print.cpp:7:
33
pure2-print.cpp2:7:1: note: in expansion of macro ‘CPP2_REQUIRES_’
44
../../../include/cpp2util.h:10005:33: error: expected initializer before ‘static_assert’
55
pure2-print.cpp2:89:1: note: in expansion of macro ‘CPP2_REQUIRES_’
6-
pure2-print.cpp2:6:24: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
7-
pure2-print.cpp2:6:31: error: template definition of non-template ‘constexpr const T outer::object_alias’
6+
pure2-print.cpp2:6:29: error: ‘constexpr const T outer::object_alias’ is not a static data member of ‘class outer’
7+
pure2-print.cpp2:6:36: error: template definition of non-template ‘constexpr const T outer::object_alias’
88
pure2-print.cpp2:88:37: error: no declaration matches ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::cmp_greater_eq(sizeof (Args)..., 0)’
99
pure2-print.cpp2:88:37: note: no functions named ‘void outer::print(std::ostream&, const Args& ...) requires cpp2::cmp_greater_eq(sizeof (Args)..., 0)’
1010
pure2-print.cpp2:4:7: note: ‘class outer’ defined here

regression-tests/test-results/gcc-13/pure2-enum.cpp.execution

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
x.to_string() is clubs
22
x2.to_string() is clubs
3-
using << prints clubs
43
with if else: clubs
54
with inspect: clubs
65

regression-tests/test-results/mixed-inspect-templates.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ struct my_type {};
3232

3333
#line 8 "mixed-inspect-templates.cpp2"
3434
[[nodiscard]] auto fun(auto const& v) -> std::string{
35-
return [&] () -> std::string { auto&& __expr = v;
36-
if (cpp2::is<std::vector>(__expr)) { if constexpr( requires{"std::vector";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::vector")),std::string> ) return "std::vector"; else return std::string{}; else return std::string{}; }
37-
else if (cpp2::is<std::array>(__expr)) { if constexpr( requires{"std::array";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::array")),std::string> ) return "std::array"; else return std::string{}; else return std::string{}; }
38-
else if (cpp2::is<std::variant>(__expr)) { if constexpr( requires{"std::variant";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::variant")),std::string> ) return "std::variant"; else return std::string{}; else return std::string{}; }
39-
else if (cpp2::is<my_type>(__expr)) { if constexpr( requires{"my_type";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("my_type")),std::string> ) return "my_type"; else return std::string{}; else return std::string{}; }
35+
return [&] () -> std::string { auto&& _expr = v;
36+
if (cpp2::is<std::vector>(_expr)) { if constexpr( requires{"std::vector";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::vector")),std::string> ) return "std::vector"; else return std::string{}; else return std::string{}; }
37+
else if (cpp2::is<std::array>(_expr)) { if constexpr( requires{"std::array";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::array")),std::string> ) return "std::array"; else return std::string{}; else return std::string{}; }
38+
else if (cpp2::is<std::variant>(_expr)) { if constexpr( requires{"std::variant";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::variant")),std::string> ) return "std::variant"; else return std::string{}; else return std::string{}; }
39+
else if (cpp2::is<my_type>(_expr)) { if constexpr( requires{"my_type";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("my_type")),std::string> ) return "my_type"; else return std::string{}; else return std::string{}; }
4040
else return "unknown"; }
4141
();
4242
}

regression-tests/test-results/mixed-inspect-values-2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ constexpr auto empty = [](auto&& x){
3838
[[nodiscard]] auto main() -> int{
3939
auto i {15};
4040

41-
std::cout << [&] () -> std::string { auto&& __expr = i;
42-
if (cpp2::is(__expr, (less_than(10)))) { if constexpr( requires{"i less than 10";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i less than 10")),std::string> ) return "i less than 10"; else return std::string{}; else return std::string{}; }
43-
else if (cpp2::is(__expr, in(11, 20))) { if constexpr( requires{"i is between 11 and 20";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i is between 11 and 20")),std::string> ) return "i is between 11 and 20"; else return std::string{}; else return std::string{}; }
41+
std::cout << [&] () -> std::string { auto&& _expr = i;
42+
if (cpp2::is(_expr, (less_than(10)))) { if constexpr( requires{"i less than 10";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i less than 10")),std::string> ) return "i less than 10"; else return std::string{}; else return std::string{}; }
43+
else if (cpp2::is(_expr, in(11, 20))) { if constexpr( requires{"i is between 11 and 20";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i is between 11 and 20")),std::string> ) return "i is between 11 and 20"; else return std::string{}; else return std::string{}; }
4444
else return "i is out of our interest"; }
4545
() << std::endl;
4646

regression-tests/test-results/mixed-inspect-values.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ auto test(auto const& x) -> void;
5555

5656
auto test(auto const& x) -> void{
5757
auto forty_two {42};
58-
std::cout << [&] () -> std::string { auto&& __expr = x;
59-
if (cpp2::is(__expr, 0)) { if constexpr( requires{"zero";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("zero")),std::string> ) return "zero"; else return std::string{}; else return std::string{}; }
60-
else if (cpp2::is(__expr, (in(1, 2)))) { if constexpr( requires{"1 or 2";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("1 or 2")),std::string> ) return "1 or 2"; else return std::string{}; else return std::string{}; }
61-
else if (cpp2::is(__expr, in_2_3)) { if constexpr( requires{"3";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("3")),std::string> ) return "3"; else return std::string{}; else return std::string{}; }
62-
else if (cpp2::is(__expr, std::move(forty_two))) { if constexpr( requires{"the answer";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("the answer")),std::string> ) return "the answer"; else return std::string{}; else return std::string{}; }
63-
else if (cpp2::is<int>(__expr)) { if constexpr( requires{"integer " + cpp2::to_string(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("integer " + cpp2::to_string(x))),std::string> ) return "integer " + cpp2::to_string(x); else return std::string{}; else return std::string{}; }
64-
else if (cpp2::is<std::string>(__expr)) { if constexpr( requires{cpp2::as<std::string>(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((cpp2::as<std::string>(x))),std::string> ) return cpp2::as<std::string>(x); else return std::string{}; else return std::string{}; }
58+
std::cout << [&] () -> std::string { auto&& _expr = x;
59+
if (cpp2::is(_expr, 0)) { if constexpr( requires{"zero";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("zero")),std::string> ) return "zero"; else return std::string{}; else return std::string{}; }
60+
else if (cpp2::is(_expr, (in(1, 2)))) { if constexpr( requires{"1 or 2";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("1 or 2")),std::string> ) return "1 or 2"; else return std::string{}; else return std::string{}; }
61+
else if (cpp2::is(_expr, in_2_3)) { if constexpr( requires{"3";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("3")),std::string> ) return "3"; else return std::string{}; else return std::string{}; }
62+
else if (cpp2::is(_expr, std::move(forty_two))) { if constexpr( requires{"the answer";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("the answer")),std::string> ) return "the answer"; else return std::string{}; else return std::string{}; }
63+
else if (cpp2::is<int>(_expr)) { if constexpr( requires{"integer " + cpp2::to_string(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("integer " + cpp2::to_string(x))),std::string> ) return "integer " + cpp2::to_string(x); else return std::string{}; else return std::string{}; }
64+
else if (cpp2::is<std::string>(_expr)) { if constexpr( requires{cpp2::as<std::string>(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((cpp2::as<std::string>(x))),std::string> ) return cpp2::as<std::string>(x); else return std::string{}; else return std::string{}; }
6565
else return "(no match)"; }
6666
() << "\n";
6767
}

regression-tests/test-results/mixed-inspect-with-typeof-of-template-arg-list.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ auto calc() {
2828

2929
#line 7 "mixed-inspect-with-typeof-of-template-arg-list.cpp2"
3030
[[nodiscard]] auto fun(auto const& v) -> int{
31-
return [&] () -> int { auto&& __expr = v;
32-
if (cpp2::is<int>(__expr)) { if constexpr( requires{calc<1,2>();} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((calc<1,2>())),int> ) return calc<1,2>(); else return int{}; else return int{}; }
31+
return [&] () -> int { auto&& _expr = v;
32+
if (cpp2::is<int>(_expr)) { if constexpr( requires{calc<1,2>();} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((calc<1,2>())),int> ) return calc<1,2>(); else return int{}; else return int{}; }
3333
else return 0; }
3434
();
3535
}

regression-tests/test-results/mixed-multiple-return-values.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#include <iostream>
1414
#include <random>
1515
#include <string>
16-
struct f__ret { int i; std::string s; };
16+
struct f_ret { int i; std::string s; };
1717

1818
#line 6 "mixed-multiple-return-values.cpp2"
19-
[[nodiscard]] auto f() -> f__ret;
19+
[[nodiscard]] auto f() -> f_ret;
2020

2121

2222
#line 22 "mixed-multiple-return-values.cpp2"
@@ -40,7 +40,7 @@ bool flip_a_coin() {
4040

4141

4242
#line 6 "mixed-multiple-return-values.cpp2"
43-
[[nodiscard]] auto f() -> f__ret{
43+
[[nodiscard]] auto f() -> f_ret{
4444
cpp2::deferred_init<int> i;
4545
cpp2::deferred_init<std::string> s;
4646
// note: i and s are uninitialized!

regression-tests/test-results/msvc-2022/pure2-enum.cpp.execution

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
x.to_string() is clubs
22
x2.to_string() is clubs
3-
using << prints clubs
43
with if else: clubs
54
with inspect: clubs
65

regression-tests/test-results/pure2-bugfix-for-name-lookup-and-value-decoration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

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

13-
struct vals__ret { int i; };
13+
struct vals_ret { int i; };
1414

15-
[[nodiscard]] auto vals() -> vals__ret;
15+
[[nodiscard]] auto vals() -> vals_ret;
1616

1717

1818
#line 6 "pure2-bugfix-for-name-lookup-and-value-decoration.cpp2"
@@ -21,7 +21,7 @@ struct vals__ret { int i; };
2121

2222
//=== Cpp2 function definitions =================================================
2323

24-
[[nodiscard]] auto vals() -> vals__ret{
24+
[[nodiscard]] auto vals() -> vals_ret{
2525
cpp2::deferred_init<int> i;
2626
#line 2 "pure2-bugfix-for-name-lookup-and-value-decoration.cpp2"
2727
i.construct(42);

regression-tests/test-results/pure2-cpp1-multitoken-fundamental-types-error.cpp2.output

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ pure2-cpp1-multitoken-fundamental-types-error.cpp2(3,8): error: 'signed short in
33
pure2-cpp1-multitoken-fundamental-types-error.cpp2(3,8): error: 'signed short int' is an old-style C/C++ multi-word keyword type
44
- most such types should be used only for interoperability with older code
55
- using those when you need them is fine, but name them with these short names instead:
6-
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, __schar, __uchar
6+
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar
77
- see also cpp2util.h > "Convenience names for integer types"
88
pure2-cpp1-multitoken-fundamental-types-error.cpp2(4,8): error: 'short int signed' - did you mean 'short'?
99
pure2-cpp1-multitoken-fundamental-types-error.cpp2(4,8): error: 'short int signed' is an old-style C/C++ multi-word keyword type
1010
- most such types should be used only for interoperability with older code
1111
- using those when you need them is fine, but name them with these short names instead:
12-
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, __schar, __uchar
12+
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar
1313
- see also cpp2util.h > "Convenience names for integer types"
1414
pure2-cpp1-multitoken-fundamental-types-error.cpp2(5,8): error: 'long long unsigned int' - did you mean 'ulonglong'?
1515
pure2-cpp1-multitoken-fundamental-types-error.cpp2(5,8): error: 'long long unsigned int' is an old-style C/C++ multi-word keyword type
1616
- most such types should be used only for interoperability with older code
1717
- using those when you need them is fine, but name them with these short names instead:
18-
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, __schar, __uchar
18+
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar
1919
- see also cpp2util.h > "Convenience names for integer types"
2020
pure2-cpp1-multitoken-fundamental-types-error.cpp2(6,8): error: 'long double' - did you mean 'long'?
2121
pure2-cpp1-multitoken-fundamental-types-error.cpp2(6,8): error: 'long double' is an old-style C/C++ multi-word keyword type
2222
- most such types should be used only for interoperability with older code
2323
- using those when you need them is fine, but name them with these short names instead:
24-
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, __schar, __uchar
24+
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar
2525
- see also cpp2util.h > "Convenience names for integer types"
26-
pure2-cpp1-multitoken-fundamental-types-error.cpp2(7,8): error: 'unsigned char' - did you mean 'u8' (usually best) or 'cpp2::__uchar'?
26+
pure2-cpp1-multitoken-fundamental-types-error.cpp2(7,8): error: 'unsigned char' - did you mean 'u8' (usually best) or 'cpp2::_uchar'?
2727
pure2-cpp1-multitoken-fundamental-types-error.cpp2(7,8): error: 'unsigned char' is an old-style C/C++ multi-word keyword type
2828
- most such types should be used only for interoperability with older code
2929
- using those when you need them is fine, but name them with these short names instead:
30-
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, __schar, __uchar
30+
short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar
3131
- see also cpp2util.h > "Convenience names for integer types"
3232

0 commit comments

Comments
 (0)