diff --git a/include/cpp2util.h b/include/cpp2util.h index 8ee7792c8d..635c5f75b0 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -205,6 +205,7 @@ #include #include #include + #include #include #include #include @@ -1490,16 +1491,17 @@ inline auto to_string(std::tuple const& t) -> std::string // struct args_t : std::vector { - args_t(int c, char const* const* v) : vector{static_cast(c)}, argc{c}, argv{v} {} + args_t(int c, char** v) : vector{static_cast(c)}, argc{c}, argv{v}, mutable_argv{v} {} - int argc = 0; - char const* const* argv = nullptr; + int argc = 0; + char const* const* argv = nullptr; + char** mutable_argv = nullptr; }; -inline auto make_args(int argc, char const* const* argv) -> args_t +inline auto make_args(int argc, char** argv) -> args_t { auto ret = args_t{argc, argv}; - std::copy(argv, argv + argc, ret.data()); + std::ranges::copy( std::span(argv, argc), ret.data() ); return ret; } diff --git a/regression-tests/pure2-main-args.cpp2 b/regression-tests/pure2-main-args.cpp2 index 44daf2c9bb..d5775a23ab 100644 --- a/regression-tests/pure2-main-args.cpp2 +++ b/regression-tests/pure2-main-args.cpp2 @@ -1,2 +1,6 @@ main: (args) = - std::cout << "args.argc is (args.argc)$, and args.argv[0] is (args.argv[0])$\n"; + std::cout + << "args.argc is (args.argc)$\n" + << "args.argv[0] is (args.argv[0])$\n" + << "args.mutable_argv[0] is (args.mutable_argv[0])$\n" + ; diff --git a/regression-tests/test-results/clang-12/pure2-main-args.cpp.execution b/regression-tests/test-results/clang-12/pure2-main-args.cpp.execution index 9b58eb7056..ff4e788b82 100644 --- a/regression-tests/test-results/clang-12/pure2-main-args.cpp.execution +++ b/regression-tests/test-results/clang-12/pure2-main-args.cpp.execution @@ -1 +1,3 @@ -args.argc is 1, and args.argv[0] is ./test.exe +args.argc is 1 +args.argv[0] is ./test.exe +args.mutable_argv[0] is ./test.exe diff --git a/regression-tests/test-results/gcc-13/pure2-main-args.cpp.execution b/regression-tests/test-results/gcc-13/pure2-main-args.cpp.execution index 9b58eb7056..ff4e788b82 100644 --- a/regression-tests/test-results/gcc-13/pure2-main-args.cpp.execution +++ b/regression-tests/test-results/gcc-13/pure2-main-args.cpp.execution @@ -1 +1,3 @@ -args.argc is 1, and args.argv[0] is ./test.exe +args.argc is 1 +args.argv[0] is ./test.exe +args.mutable_argv[0] is ./test.exe diff --git a/regression-tests/test-results/mixed-fixed-type-aliases.cpp b/regression-tests/test-results/mixed-fixed-type-aliases.cpp index 25a2a41a0c..72e78db71d 100644 --- a/regression-tests/test-results/mixed-fixed-type-aliases.cpp +++ b/regression-tests/test-results/mixed-fixed-type-aliases.cpp @@ -21,7 +21,7 @@ auto test(auto const& x) -> void; #line 15 "mixed-fixed-type-aliases.cpp2" -[[nodiscard]] auto main(int const argc_, char const* const* const argv_) -> int; +[[nodiscard]] auto main(int const argc_, char** argv_) -> int; //=== Cpp2 function definitions ================================================= @@ -35,7 +35,7 @@ auto test(auto const& x) -> void{ << "\n"; } -[[nodiscard]] auto main(int const argc_, char const* const* const argv_) -> int{ +[[nodiscard]] auto main(int const argc_, char** argv_) -> int{ auto args = cpp2::make_args(argc_, argv_); #line 16 "mixed-fixed-type-aliases.cpp2" my::u16 y {42}; diff --git a/regression-tests/test-results/msvc-2022/pure2-main-args.cpp.execution b/regression-tests/test-results/msvc-2022/pure2-main-args.cpp.execution index 35a53cee32..e8c170a1e8 100644 --- a/regression-tests/test-results/msvc-2022/pure2-main-args.cpp.execution +++ b/regression-tests/test-results/msvc-2022/pure2-main-args.cpp.execution @@ -1 +1,3 @@ -args.argc is 1, and args.argv[0] is test.exe +args.argc is 1 +args.argv[0] is test.exe +args.mutable_argv[0] is test.exe diff --git a/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp b/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp index 292b8185e0..48281a6888 100644 --- a/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp +++ b/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp @@ -26,7 +26,7 @@ class quantity { #line 5 "pure2-bugfix-for-discard-precedence.cpp2" }; -auto main(int const argc_, char const* const* const argv_) -> int; +auto main(int const argc_, char** argv_) -> int; //=== Cpp2 function definitions ================================================= @@ -46,7 +46,7 @@ auto main(int const argc_, char const* const* const argv_) -> int; [[nodiscard]] auto quantity::operator+(quantity const& that) -> quantity { return quantity(number + that.number); } #line 7 "pure2-bugfix-for-discard-precedence.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int{ +auto main(int const argc_, char** argv_) -> int{ auto args = cpp2::make_args(argc_, argv_); #line 8 "pure2-bugfix-for-discard-precedence.cpp2" quantity x {1729}; diff --git a/regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp b/regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp index 406dafcf16..0ce6486cdd 100644 --- a/regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp +++ b/regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp @@ -11,13 +11,13 @@ //=== Cpp2 type definitions and function declarations =========================== #line 1 "pure2-initialization-safety-with-else-if.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int; +auto main(int const argc_, char** argv_) -> int; //=== Cpp2 function definitions ================================================= #line 1 "pure2-initialization-safety-with-else-if.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int{ +auto main(int const argc_, char** argv_) -> int{ auto args = cpp2::make_args(argc_, argv_); #line 2 "pure2-initialization-safety-with-else-if.cpp2" cpp2::deferred_init p; diff --git a/regression-tests/test-results/pure2-main-args.cpp b/regression-tests/test-results/pure2-main-args.cpp index f3e00e0a64..86cee033cd 100644 --- a/regression-tests/test-results/pure2-main-args.cpp +++ b/regression-tests/test-results/pure2-main-args.cpp @@ -11,14 +11,17 @@ //=== Cpp2 type definitions and function declarations =========================== #line 1 "pure2-main-args.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int; +auto main(int const argc_, char** argv_) -> int; //=== Cpp2 function definitions ================================================= #line 1 "pure2-main-args.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int { +auto main(int const argc_, char** argv_) -> int { auto args = cpp2::make_args(argc_, argv_); #line 2 "pure2-main-args.cpp2" - std::cout << "args.argc is " + cpp2::to_string(args.argc) + ", and args.argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.argv, 0)) + "\n"; } + std::cout + << "args.argc is " + cpp2::to_string(args.argc) + "\n" + << "args.argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.argv, 0)) + "\n" + << "args.mutable_argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.mutable_argv, 0)) + "\n"; } diff --git a/regression-tests/test-results/pure2-statement-scope-parameters.cpp b/regression-tests/test-results/pure2-statement-scope-parameters.cpp index 18c86ff80e..91134990ee 100644 --- a/regression-tests/test-results/pure2-statement-scope-parameters.cpp +++ b/regression-tests/test-results/pure2-statement-scope-parameters.cpp @@ -12,14 +12,14 @@ #line 2 "pure2-statement-scope-parameters.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int; +auto main(int const argc_, char** argv_) -> int; //=== Cpp2 function definitions ================================================= #line 2 "pure2-statement-scope-parameters.cpp2" -auto main(int const argc_, char const* const* const argv_) -> int{ +auto main(int const argc_, char** argv_) -> int{ auto args = cpp2::make_args(argc_, argv_); #line 3 "pure2-statement-scope-parameters.cpp2" auto local_int {42}; diff --git a/regression-tests/test-results/version b/regression-tests/test-results/version index eea4cf89b7..0cdff82017 100644 --- a/regression-tests/test-results/version +++ b/regression-tests/test-results/version @@ -1,5 +1,5 @@ -cppfront compiler v0.2.1 Build 8812:1816 +cppfront compiler v0.2.1 Build 8814:1300 Copyright(c) Herb Sutter All rights reserved SPDX-License-Identifier: CC-BY-NC-ND-4.0 diff --git a/source/build.info b/source/build.info index 9e125a11eb..fe227e2121 100644 --- a/source/build.info +++ b/source/build.info @@ -1 +1 @@ -"8812:1816" \ No newline at end of file +"8814:1300" \ No newline at end of file diff --git a/source/cppfront.cpp b/source/cppfront.cpp index 8ce4aca99e..b1e39a22e0 100644 --- a/source/cppfront.cpp +++ b/source/cppfront.cpp @@ -4260,7 +4260,7 @@ class cppfront ) { printer.print_cpp2( - "(int const argc_, char const* const* const argv_)", + "(int const argc_, char** argv_)", n.parameters->position() ); current_functions.back().prolog.statements.push_back(