Skip to content

Commit

Permalink
Merge branch 'main' into feature/regular_expression_metafunction
Browse files Browse the repository at this point in the history
Signed-off-by: Herb Sutter <[email protected]>
  • Loading branch information
hsutter authored Jul 21, 2024
2 parents de8348f + e45eae5 commit ae9fa61
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ auto call_my_framework(const char* msg CPP2_SOURCE_LOCATION_PARAM) {
std::cout
<< "from source location: "
<< loc
<< "]\n";
<< "\n";
}
exit(0);
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: ../../../include/cpp2util.h(673) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]]
from source location: ../../../include/cpp2util.h(669) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: ../../../include/cpp2util.h(673) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]]
from source location: ../../../include/cpp2util.h(669) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void try_pointer_stuff()
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ auto call_my_framework(const char* msg CPP2_SOURCE_LOCATION_PARAM) {
std::cout
<< "from source location: "
<< loc
<< "]\n";
<< "\n";
}
exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sending error to my framework... [dynamic null dereference attempt detected]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)]
from source location: mixed-lifetime-safety-and-null-contracts.cpp2(17) void __cdecl try_pointer_stuff(void)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pure2-return-tuple-no-identifier-error.cpp2...
pure2-return-tuple-no-identifier-error.cpp2(1,11): error: expected identifier, not 'int'
pure2-return-tuple-no-identifier-error.cpp2(1,16): error: expected identifier, not 'int'
pure2-return-tuple-no-identifier-error.cpp2(1,14): error: missing function return after -> (at ',')

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pure2-return-tuple-no-type-error.cpp2...
pure2-return-tuple-no-type-error.cpp2(1,11): error: return parameter 'a' must have a type
pure2-return-tuple-no-type-error.cpp2(1,14): error: return parameter 'b' must have a type
pure2-return-tuple-no-type-error.cpp2(1,12): error: missing function return after -> (at ',')

2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
2 changes: 1 addition & 1 deletion source/build.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"9714:0930"
"9718:1445"
12 changes: 12 additions & 0 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,18 @@ class cmdline_processor
}

public:
auto flags_starting_with(std::string_view s)
-> std::vector<std::string>
{
auto ret = std::vector<std::string>{};
for (auto const& f : flags) {
if (f.name.starts_with(s)) {
ret.push_back(f.name);
}
}
return ret;
}

auto process_flags()
-> void
{
Expand Down
18 changes: 18 additions & 0 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ auto main(
int exit_status = EXIT_SUCCESS;
for (auto const& arg : cmdline.arguments())
{
if (
arg.text.starts_with("-")
|| arg.text.starts_with("/")
)
{
auto ambiguous = cmdline.flags_starting_with(arg.text.substr(1));
if (ambiguous.empty()) {
std::cerr << arg.text << " - unknown compiler flag name (try " << arg.text.front() << "help)\n";
}
else {
std::cerr << arg.text << " - ambiguous compiler flag name, did you mean one of these?\n";
for (auto a : ambiguous) {
std::cerr << " " << arg.text.front() << a << "\n";
}
}
return EXIT_FAILURE;
}

cpp2::timer t;
t.start();

Expand Down
30 changes: 21 additions & 9 deletions source/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,30 @@ class braces_tracker
// --- Preprocessor matching functions - #if/#else/#endif

// Entering an #if
auto found_pre_if() -> void {
assert(std::ssize(preprocessor) > 0);
auto found_pre_if(lineno_t) -> void {
preprocessor.push_back({});
}

// Encountered an #else
auto found_pre_else() -> void {
assert(std::ssize(preprocessor) > 1);
auto found_pre_else(lineno_t lineno) -> void {
if (std::ssize(preprocessor) < 2) {
errors.emplace_back(
lineno,
"#else does not match a prior #if"
);
}

preprocessor.back().found_preprocessor_else();
}

// Exiting an #endif
auto found_pre_endif() -> void {
assert(std::ssize(preprocessor) > 1);
auto found_pre_endif(lineno_t lineno) -> void {
if (std::ssize(preprocessor) < 2) {
errors.emplace_back(
lineno,
"#endif does not match a prior #if"
);
}

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

Expand Down Expand Up @@ -807,6 +818,7 @@ auto process_cpp2_line(
source_position(lineno, unsafe_narrow<colno_t>(ssize(line))),
std::string("line ended before character literal was terminated")
);
return false;
}

return found_end;
Expand Down Expand Up @@ -896,11 +908,11 @@ class source
{
switch (pre) {
break;case preprocessor_conditional::pre_if:
braces.found_pre_if();
braces.found_pre_if( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
break;case preprocessor_conditional::pre_else:
braces.found_pre_else();
braces.found_pre_else( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
break;case preprocessor_conditional::pre_endif:
braces.found_pre_endif();
braces.found_pre_endif( cpp2::unsafe_narrow<lineno_t>(std::ssize(lines)) );
break;default:
assert(false);
}
Expand Down
28 changes: 24 additions & 4 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,8 @@ auto lex_line(
" short, ushort, int, uint, long, ulong, longlong, ulonglong, longdouble, _schar, _uchar\n"
" - see also cpp2util.h > \"Convenience names for integer types\""
);

return;
}

tokens.push_back(last_token);
Expand Down Expand Up @@ -1002,6 +1004,7 @@ auto lex_line(
"invalid universal character name - \\u without { must"
" be followed by 4 hexadecimal digits"
);
return 0;
}

else if (
Expand All @@ -1022,15 +1025,16 @@ auto lex_line(

if (peek(j + offset) == '}') {
++j;
return j;
}
else {
errors.emplace_back(
source_position(lineno, i + offset),
"invalid universal character name - \\u{ must"
" be followed by hexadecimal digits and a closing }"
);
return 0;
}
return j;
}

else if (
Expand All @@ -1052,7 +1056,9 @@ auto lex_line(
"invalid universal character name - \\U must"
" be followed by 8 hexadecimal digits"
);
return 0;
}

return 0;
};

Expand Down Expand Up @@ -1352,7 +1358,7 @@ auto lex_line(
}
else { store(1, lexeme::Less); }

// Note: >> and >>= are not source tokens, they are synthesized from > > and > >= where legal
// Note: >= and >> and >>= synthesized from > = and > > and > >= where legal
//G '>>=' '>>' '>=' '>'
break;case '>':
//---------------------------------------------------------
Expand All @@ -1362,10 +1368,10 @@ auto lex_line(
// if (peek2 == '=') { store(3, lexeme::RightShiftEq); }
// else { store(2, lexeme::RightShift); }
//}
//else if (peek1 == '=') { store(2, lexeme::GreaterEq); }
//else
//---------------------------------------------------------
if (peek1 == '=') { store(2, lexeme::GreaterEq); }
else { store(1, lexeme::Greater); }
{ store(1, lexeme::Greater); }

//G '++' '+=' '+'
break;case '+':
Expand Down Expand Up @@ -1535,6 +1541,7 @@ auto lex_line(
"invalid new-line in raw string delimiter \"" + line.substr(i, 3)
+ "\" - stray 'R' in program \""
);
return {};
}
} else {
store(1, lexeme::Dollar);
Expand Down Expand Up @@ -1579,6 +1586,7 @@ auto lex_line(
source_position(lineno, i),
"binary literal cannot be empty (0B must be followed by binary digits)"
);
return {};
}
}
else if (peek1 == 'x' || peek1 == 'X') {
Expand All @@ -1592,6 +1600,7 @@ auto lex_line(
source_position(lineno, i),
"hexadecimal literal cannot be empty (0X must be followed by hexadecimal digits)"
);
return {};
}
}
}
Expand Down Expand Up @@ -1658,6 +1667,7 @@ auto lex_line(
source_position(lineno, i),
"a floating point literal must have at least one digit after the decimal point (can be '.0')"
);
return {};
}
while (is_separator_or(is_digit,peek(j))) {
++j;
Expand Down Expand Up @@ -1725,6 +1735,7 @@ auto lex_line(
"invalid new-line in raw string delimiter \"" + line.substr(i, j)
+ "\" - stray 'R' in program \""
);
return {};
}
}
else {
Expand All @@ -1735,6 +1746,7 @@ auto lex_line(
"string literal \"" + line.substr(i+1, j)
+ "\" is missing its closing \""
);
return {};
}

// At this point we have a string-literal, but it may contain
Expand Down Expand Up @@ -1782,6 +1794,7 @@ auto lex_line(
"character literal '" + line.substr(i+1, j-1)
+ "' is missing its closing '"
);
return {};
}
store(j+1, lexeme::CharacterLiteral);
}
Expand All @@ -1790,6 +1803,7 @@ auto lex_line(
source_position(lineno, i),
"character literal is empty"
);
return {};
}
}

Expand All @@ -1815,18 +1829,21 @@ auto lex_line(
source_position(lineno, i),
"'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"
);
return {};
}
if (tokens.back() == "static_cast") {
errors.emplace_back(
source_position(lineno, i),
"'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"
);
return {};
}
if (tokens.back() == "dynamic_cast") {
errors.emplace_back(
source_position(lineno, i),
"'dynamic_cast<Derived*>(pBase)' is not supported in Cpp2 - use 'pBase as *Derived' for safe dynamic conversions instead"
);
return {};
}
}

Expand All @@ -1853,12 +1870,14 @@ auto lex_line(
source_position(lineno, i),
"'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"
);
return {};
}
if (tokens.back() == "delete") {
errors.emplace_back(
source_position(lineno, i),
"'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)"
);
return {};
}
}
}
Expand All @@ -1872,6 +1891,7 @@ auto lex_line(
false,
true // a noisy fallback error message
);
return {};
}
}
}
Expand Down
Loading

0 comments on commit ae9fa61

Please sign in to comment.