From 5663493860a5558a3d64c59ac9ee6f0e26dedf99 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Wed, 20 Mar 2024 20:46:47 -1000 Subject: [PATCH] Remove whitespace sensitivity for `*` and `&` Undo commit 30c79a0 Updates comment on partly-related #152 Closes #319 Closes #989 --- regression-tests/mixed-test-parens.cpp2 | 6 ++++- .../clang-12/mixed-test-parens.cpp.execution | 4 +++- .../gcc-10/mixed-test-parens.cpp.execution | 4 +++- .../gcc-13/mixed-test-parens.cpp.execution | 4 +++- .../test-results/mixed-test-parens.cpp | 4 ++++ .../msvc-2022/mixed-test-parens.cpp.execution | 4 +++- source/parse.h | 23 +++---------------- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/regression-tests/mixed-test-parens.cpp2 b/regression-tests/mixed-test-parens.cpp2 index 0afba5af1..c90e32ec3 100644 --- a/regression-tests/mixed-test-parens.cpp2 +++ b/regression-tests/mixed-test-parens.cpp2 @@ -6,8 +6,12 @@ auto f(auto, auto) -> void { } constexpr int a = 1; main: () -> int = { + p := new(11); + std::cout << p * << "\n"; + v : std::vector = ( 1, 2, 3 ); - std::cout << (1+2) * (3+v[0]); + std::cout << (1+2)*(3+v[0]); + std::cout << "\n13*14 is (13*14)$\n"; f<(1>2)>(3,4); f< a+a >(5,6); } diff --git a/regression-tests/test-results/clang-12/mixed-test-parens.cpp.execution b/regression-tests/test-results/clang-12/mixed-test-parens.cpp.execution index 3cacc0b93..59967f29d 100644 --- a/regression-tests/test-results/clang-12/mixed-test-parens.cpp.execution +++ b/regression-tests/test-results/clang-12/mixed-test-parens.cpp.execution @@ -1 +1,3 @@ -12 \ No newline at end of file +11 +12 +13*14 is 182 diff --git a/regression-tests/test-results/gcc-10/mixed-test-parens.cpp.execution b/regression-tests/test-results/gcc-10/mixed-test-parens.cpp.execution index 3cacc0b93..59967f29d 100644 --- a/regression-tests/test-results/gcc-10/mixed-test-parens.cpp.execution +++ b/regression-tests/test-results/gcc-10/mixed-test-parens.cpp.execution @@ -1 +1,3 @@ -12 \ No newline at end of file +11 +12 +13*14 is 182 diff --git a/regression-tests/test-results/gcc-13/mixed-test-parens.cpp.execution b/regression-tests/test-results/gcc-13/mixed-test-parens.cpp.execution index 3cacc0b93..59967f29d 100644 --- a/regression-tests/test-results/gcc-13/mixed-test-parens.cpp.execution +++ b/regression-tests/test-results/gcc-13/mixed-test-parens.cpp.execution @@ -1 +1,3 @@ -12 \ No newline at end of file +11 +12 +13*14 is 182 diff --git a/regression-tests/test-results/mixed-test-parens.cpp b/regression-tests/test-results/mixed-test-parens.cpp index cb058733c..19e494367 100644 --- a/regression-tests/test-results/mixed-test-parens.cpp +++ b/regression-tests/test-results/mixed-test-parens.cpp @@ -27,8 +27,12 @@ constexpr int a = 1; #line 8 "mixed-test-parens.cpp2" [[nodiscard]] auto main() -> int{ + auto p {cpp2_new(11)}; + std::cout << *cpp2::impl::assert_not_null(cpp2::move(p)) << "\n"; + std::vector v {1, 2, 3}; std::cout << (1 + 2) * (3 + CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(v), 0)); + std::cout << ("\n13*14 is " + cpp2::to_string(13 * 14) + "\n"); f<(cpp2::impl::cmp_greater(1,2))>(3, 4); f(5, 6); } diff --git a/regression-tests/test-results/msvc-2022/mixed-test-parens.cpp.execution b/regression-tests/test-results/msvc-2022/mixed-test-parens.cpp.execution index 3cacc0b93..59967f29d 100644 --- a/regression-tests/test-results/msvc-2022/mixed-test-parens.cpp.execution +++ b/regression-tests/test-results/msvc-2022/mixed-test-parens.cpp.execution @@ -1 +1,3 @@ -12 \ No newline at end of file +11 +12 +13*14 is 182 diff --git a/source/parse.h b/source/parse.h index 463cda06e..c543c12cf 100644 --- a/source/parse.h +++ b/source/parse.h @@ -5771,7 +5771,7 @@ class parser //G postfix-expression: //G primary-expression - //G postfix-expression postfix-operator // Note: without whitespace before the operator + //G postfix-expression postfix-operator //G postfix-expression '[' expression-list? ','? ']' //G postfix-expression '(' expression-list? ','? ')' //G postfix-expression '.' id-expression @@ -5788,23 +5788,18 @@ class parser while ( !done() && ( - (is_postfix_operator(curr().type()) - // Postfix operators must be lexically adjacent - && curr().position().lineno == peek(-1)->position().lineno - && curr().position().colno == peek(-1)->position().colno + peek(-1)->length() - ) + is_postfix_operator(curr().type()) || curr().type() == lexeme::LeftBracket || curr().type() == lexeme::LeftParen || curr().type() == lexeme::Dot ) ) { - // these can't be unary operators if followed by a (, identifier, or literal + // * and & can't be unary operators if followed by a (, identifier, or literal if ( ( curr().type() == lexeme::Multiply || curr().type() == lexeme::Ampersand - || curr().type() == lexeme::Tilde ) && peek(1) && ( @@ -5814,18 +5809,6 @@ class parser ) ) { - auto op = curr().to_string(); - auto msg = "postfix unary " + op; - if (curr().type() == lexeme::Multiply ) { msg += " (dereference)" ; } - else if (curr().type() == lexeme::Ampersand) { msg += " (address-of)" ; } - else if (curr().type() == lexeme::Tilde ) { msg += " (unary bit-complement)" ; } - msg += " cannot be immediately followed by a (, identifier, or literal - add whitespace before " - + op + " here if you meant binary " + op; - if (curr().type() == lexeme::Multiply ) { msg += " (multiplication)" ; } - else if (curr().type() == lexeme::Ampersand) { msg += " (bitwise and)" ; } - else if (curr().type() == lexeme::Tilde ) { msg += " (binary bit-complement)"; } - - error(msg, false); break; }