Skip to content

Commit ae9fa61

Browse files
authored
Merge branch 'main' into feature/regular_expression_metafunction
Signed-off-by: Herb Sutter <[email protected]>
2 parents de8348f + e45eae5 commit ae9fa61

20 files changed

+187
-61
lines changed

regression-tests/mixed-lifetime-safety-and-null-contracts.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ auto call_my_framework(const char* msg CPP2_SOURCE_LOCATION_PARAM) {
2828
std::cout
2929
<< "from source location: "
3030
<< loc
31-
<< "]\n";
31+
<< "\n";
3232
}
3333
exit(0);
3434
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: ../../../include/cpp2util.h(673) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]]
2+
from source location: ../../../include/cpp2util.h(669) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: ../../../include/cpp2util.h(673) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]]
2+
from source location: ../../../include/cpp2util.h(669) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()

regression-tests/test-results/mixed-lifetime-safety-and-null-contracts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ auto call_my_framework(const char* msg CPP2_SOURCE_LOCATION_PARAM) {
3636
std::cout
3737
<< "from source location: "
3838
<< loc
39-
<< "]\n";
39+
<< "\n";
4040
}
4141
exit(0);
4242
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)]
2+
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pure2-return-tuple-no-identifier-error.cpp2...
22
pure2-return-tuple-no-identifier-error.cpp2(1,11): error: expected identifier, not 'int'
3-
pure2-return-tuple-no-identifier-error.cpp2(1,16): error: expected identifier, not 'int'
3+
pure2-return-tuple-no-identifier-error.cpp2(1,14): error: missing function return after -> (at ',')
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pure2-return-tuple-no-type-error.cpp2...
22
pure2-return-tuple-no-type-error.cpp2(1,11): error: return parameter 'a' must have a type
3-
pure2-return-tuple-no-type-error.cpp2(1,14): error: return parameter 'b' must have a type
3+
pure2-return-tuple-no-type-error.cpp2(1,12): error: missing function return after -> (at ',')
44

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.7.1 Build 9714:0930
2+
cppfront compiler v0.7.1 Build 9718:1445
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"9714:0930"
1+
"9718:1445"

source/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,18 @@ class cmdline_processor
669669
}
670670

671671
public:
672+
auto flags_starting_with(std::string_view s)
673+
-> std::vector<std::string>
674+
{
675+
auto ret = std::vector<std::string>{};
676+
for (auto const& f : flags) {
677+
if (f.name.starts_with(s)) {
678+
ret.push_back(f.name);
679+
}
680+
}
681+
return ret;
682+
}
683+
672684
auto process_flags()
673685
-> void
674686
{

source/cppfront.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ auto main(
6161
int exit_status = EXIT_SUCCESS;
6262
for (auto const& arg : cmdline.arguments())
6363
{
64+
if (
65+
arg.text.starts_with("-")
66+
|| arg.text.starts_with("/")
67+
)
68+
{
69+
auto ambiguous = cmdline.flags_starting_with(arg.text.substr(1));
70+
if (ambiguous.empty()) {
71+
std::cerr << arg.text << " - unknown compiler flag name (try " << arg.text.front() << "help)\n";
72+
}
73+
else {
74+
std::cerr << arg.text << " - ambiguous compiler flag name, did you mean one of these?\n";
75+
for (auto a : ambiguous) {
76+
std::cerr << " " << arg.text.front() << a << "\n";
77+
}
78+
}
79+
return EXIT_FAILURE;
80+
}
81+
6482
cpp2::timer t;
6583
t.start();
6684

source/io.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,30 @@ class braces_tracker
461461
// --- Preprocessor matching functions - #if/#else/#endif
462462

463463
// Entering an #if
464-
auto found_pre_if() -> void {
465-
assert(std::ssize(preprocessor) > 0);
464+
auto found_pre_if(lineno_t) -> void {
466465
preprocessor.push_back({});
467466
}
468467

469468
// Encountered an #else
470-
auto found_pre_else() -> void {
471-
assert(std::ssize(preprocessor) > 1);
469+
auto found_pre_else(lineno_t lineno) -> void {
470+
if (std::ssize(preprocessor) < 2) {
471+
errors.emplace_back(
472+
lineno,
473+
"#else does not match a prior #if"
474+
);
475+
}
476+
472477
preprocessor.back().found_preprocessor_else();
473478
}
474479

475480
// Exiting an #endif
476-
auto found_pre_endif() -> void {
477-
assert(std::ssize(preprocessor) > 1);
481+
auto found_pre_endif(lineno_t lineno) -> void {
482+
if (std::ssize(preprocessor) < 2) {
483+
errors.emplace_back(
484+
lineno,
485+
"#endif does not match a prior #if"
486+
);
487+
}
478488

479489
// If the #if/#else/#endif introduced the same net number of braces,
480490
// then we will have recorded that number too many open braces, and
@@ -779,6 +789,7 @@ auto process_cpp2_line(
779789
" after the closing ; or } of a definition, the rest"
780790
" of the line cannot begin a /*...*/ comment")
781791
);
792+
return false;
782793
}
783794
}
784795

@@ -807,6 +818,7 @@ auto process_cpp2_line(
807818
source_position(lineno, unsafe_narrow<colno_t>(ssize(line))),
808819
std::string("line ended before character literal was terminated")
809820
);
821+
return false;
810822
}
811823

812824
return found_end;
@@ -896,11 +908,11 @@ class source
896908
{
897909
switch (pre) {
898910
break;case preprocessor_conditional::pre_if:
899-
braces.found_pre_if();
911+
braces.found_pre_if( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
900912
break;case preprocessor_conditional::pre_else:
901-
braces.found_pre_else();
913+
braces.found_pre_else( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
902914
break;case preprocessor_conditional::pre_endif:
903-
braces.found_pre_endif();
915+
braces.found_pre_endif( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
904916
break;default:
905917
assert(false);
906918
}

source/lex.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ auto lex_line(
751751
" short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar\n"
752752
" - see also cpp2util.h > \"Convenience names for integer types\""
753753
);
754+
755+
return;
754756
}
755757

756758
tokens.push_back(last_token);
@@ -1002,6 +1004,7 @@ auto lex_line(
10021004
"invalid universal character name - \\u without { must"
10031005
" be followed by 4 hexadecimal digits"
10041006
);
1007+
return 0;
10051008
}
10061009

10071010
else if (
@@ -1022,15 +1025,16 @@ auto lex_line(
10221025

10231026
if (peek(j + offset) == '}') {
10241027
++j;
1028+
return j;
10251029
}
10261030
else {
10271031
errors.emplace_back(
10281032
source_position(lineno, i + offset),
10291033
"invalid universal character name - \\u{ must"
10301034
" be followed by hexadecimal digits and a closing }"
10311035
);
1036+
return 0;
10321037
}
1033-
return j;
10341038
}
10351039

10361040
else if (
@@ -1052,7 +1056,9 @@ auto lex_line(
10521056
"invalid universal character name - \\U must"
10531057
" be followed by 8 hexadecimal digits"
10541058
);
1059+
return 0;
10551060
}
1061+
10561062
return 0;
10571063
};
10581064

@@ -1352,7 +1358,7 @@ auto lex_line(
13521358
}
13531359
else { store(1, lexeme::Less); }
13541360

1355-
// Note: >> and >>= are not source tokens, they are synthesized from > > and > >= where legal
1361+
// Note: >= and >> and >>= synthesized from > = and > > and > >= where legal
13561362
//G '>>=' '>>' '>=' '>'
13571363
break;case '>':
13581364
//---------------------------------------------------------
@@ -1362,10 +1368,10 @@ auto lex_line(
13621368
// if (peek2 == '=') { store(3, lexeme::RightShiftEq); }
13631369
// else { store(2, lexeme::RightShift); }
13641370
//}
1371+
//else if (peek1 == '=') { store(2, lexeme::GreaterEq); }
13651372
//else
13661373
//---------------------------------------------------------
1367-
if (peek1 == '=') { store(2, lexeme::GreaterEq); }
1368-
else { store(1, lexeme::Greater); }
1374+
{ store(1, lexeme::Greater); }
13691375

13701376
//G '++' '+=' '+'
13711377
break;case '+':
@@ -1535,6 +1541,7 @@ auto lex_line(
15351541
"invalid new-line in raw string delimiter \"" + line.substr(i, 3)
15361542
+ "\" - stray 'R' in program \""
15371543
);
1544+
return {};
15381545
}
15391546
} else {
15401547
store(1, lexeme::Dollar);
@@ -1579,6 +1586,7 @@ auto lex_line(
15791586
source_position(lineno, i),
15801587
"binary literal cannot be empty (0B must be followed by binary digits)"
15811588
);
1589+
return {};
15821590
}
15831591
}
15841592
else if (peek1 == 'x' || peek1 == 'X') {
@@ -1592,6 +1600,7 @@ auto lex_line(
15921600
source_position(lineno, i),
15931601
"hexadecimal literal cannot be empty (0X must be followed by hexadecimal digits)"
15941602
);
1603+
return {};
15951604
}
15961605
}
15971606
}
@@ -1658,6 +1667,7 @@ auto lex_line(
16581667
source_position(lineno, i),
16591668
"a floating point literal must have at least one digit after the decimal point (can be '.0')"
16601669
);
1670+
return {};
16611671
}
16621672
while (is_separator_or(is_digit,peek(j))) {
16631673
++j;
@@ -1725,6 +1735,7 @@ auto lex_line(
17251735
"invalid new-line in raw string delimiter \"" + line.substr(i, j)
17261736
+ "\" - stray 'R' in program \""
17271737
);
1738+
return {};
17281739
}
17291740
}
17301741
else {
@@ -1735,6 +1746,7 @@ auto lex_line(
17351746
"string literal \"" + line.substr(i+1, j)
17361747
+ "\" is missing its closing \""
17371748
);
1749+
return {};
17381750
}
17391751

17401752
// At this point we have a string-literal, but it may contain
@@ -1782,6 +1794,7 @@ auto lex_line(
17821794
"character literal '" + line.substr(i+1, j-1)
17831795
+ "' is missing its closing '"
17841796
);
1797+
return {};
17851798
}
17861799
store(j+1, lexeme::CharacterLiteral);
17871800
}
@@ -1790,6 +1803,7 @@ auto lex_line(
17901803
source_position(lineno, i),
17911804
"character literal is empty"
17921805
);
1806+
return {};
17931807
}
17941808
}
17951809

@@ -1815,18 +1829,21 @@ auto lex_line(
18151829
source_position(lineno, i),
18161830
"'const_cast' is not supported in Cpp2 - the current C++ best practice is to never cast away const, and that is const_cast's only effective use"
18171831
);
1832+
return {};
18181833
}
18191834
if (tokens.back() == "static_cast") {
18201835
errors.emplace_back(
18211836
source_position(lineno, i),
18221837
"'static_cast<T>(val)' is not supported in Cpp2 - use 'val as T' for safe conversions instead, or if necessary cpp2::unsafe_narrow<T>(val) for a possibly-lossy narrowing conversion"
18231838
);
1839+
return {};
18241840
}
18251841
if (tokens.back() == "dynamic_cast") {
18261842
errors.emplace_back(
18271843
source_position(lineno, i),
18281844
"'dynamic_cast<Derived*>(pBase)' is not supported in Cpp2 - use 'pBase as *Derived' for safe dynamic conversions instead"
18291845
);
1846+
return {};
18301847
}
18311848
}
18321849

@@ -1853,12 +1870,14 @@ auto lex_line(
18531870
source_position(lineno, i),
18541871
"'NULL' is not supported in Cpp2 - for a local pointer variable, leave it uninitialized instead, and set it to a non-null value when you have one"
18551872
);
1873+
return {};
18561874
}
18571875
if (tokens.back() == "delete") {
18581876
errors.emplace_back(
18591877
source_position(lineno, i),
18601878
"'delete' and owning raw pointers are not supported in Cpp2 - use unique.new<T> or shared.new<T> instead in that order (or, in the future, gc.new<T>, but that is not yet implemented)"
18611879
);
1880+
return {};
18621881
}
18631882
}
18641883
}
@@ -1872,6 +1891,7 @@ auto lex_line(
18721891
false,
18731892
true // a noisy fallback error message
18741893
);
1894+
return {};
18751895
}
18761896
}
18771897
}

0 commit comments

Comments
 (0)