From 11fc88d5a62a157cfbbd942ea4cb7c6efcb0024f Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Tue, 15 Aug 2023 17:28:40 -0700 Subject: [PATCH] Switched `argv` back to its usual standard meaning The real default-const value is in the safe `args` themselves, and `argc` and `argv` should be their standard selves for compatibility. See #592 comment thread, thanks @vladimir-kraus ! --- include/cpp2util.h | 12 ++++++------ regression-tests/pure2-main-args.cpp2 | 1 - .../clang-12/pure2-main-args.cpp.execution | 1 - .../gcc-13/pure2-main-args.cpp.execution | 1 - .../test-results/gcc-13/run-tests-gcc-13.sh | 2 +- .../msvc-2022/pure2-main-args.cpp.execution | 1 - regression-tests/test-results/pure2-main-args.cpp | 3 +-- regression-tests/test-results/version | 2 +- source/build.info | 2 +- 9 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/cpp2util.h b/include/cpp2util.h index 635c5f75b..85839ebcc 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -1491,17 +1491,17 @@ inline auto to_string(std::tuple const& t) -> std::string // struct args_t : std::vector { - args_t(int c, char** v) : vector{static_cast(c)}, argc{c}, argv{v}, mutable_argv{v} {} + args_t(int c, char** v) : vector{static_cast(c)}, argc{c}, argv{v} {} - int argc = 0; - char const* const* argv = nullptr; - char** mutable_argv = nullptr; + int argc = 0; + char** argv = nullptr; }; inline auto make_args(int argc, char** argv) -> args_t { - auto ret = args_t{argc, argv}; - std::ranges::copy( std::span(argv, argc), ret.data() ); + auto ret = args_t{argc, argv}; + auto args = std::span(argv, static_cast(argc)); + std::copy( args.begin(), args.end(), ret.data()); return ret; } diff --git a/regression-tests/pure2-main-args.cpp2 b/regression-tests/pure2-main-args.cpp2 index d5775a23a..ac4cba13a 100644 --- a/regression-tests/pure2-main-args.cpp2 +++ b/regression-tests/pure2-main-args.cpp2 @@ -2,5 +2,4 @@ main: (args) = 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 ff4e788b8..c0608cd2e 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,3 +1,2 @@ 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 ff4e788b8..c0608cd2e 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,3 +1,2 @@ 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/run-tests-gcc-13.sh b/regression-tests/test-results/gcc-13/run-tests-gcc-13.sh index c2ec29294..67ae42a5e 100644 --- a/regression-tests/test-results/gcc-13/run-tests-gcc-13.sh +++ b/regression-tests/test-results/gcc-13/run-tests-gcc-13.sh @@ -10,7 +10,7 @@ for f in *.cpp do let count=count+1 printf "[%s] Starting gcc 13 %s\n" "$count" "$f" - g++ -I../../../include -std=c++20 -pthread -Wunused-parameter -o test.exe $f > $f.output 2>&1 + g++ -I../../../include -std=c++20 -pthread -Wold-style-cast -Wunused-parameter -o test.exe $f > $f.output 2>&1 rm -f $f if test -f "test.exe"; then let exe_count=exe_count+1 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 e8c170a1e..bd992e432 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,3 +1,2 @@ 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-main-args.cpp b/regression-tests/test-results/pure2-main-args.cpp index 86cee033c..d58c38b7d 100644 --- a/regression-tests/test-results/pure2-main-args.cpp +++ b/regression-tests/test-results/pure2-main-args.cpp @@ -22,6 +22,5 @@ auto main(int const argc_, char** argv_) -> int { #line 2 "pure2-main-args.cpp2" 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"; } + << "args.argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.argv, 0)) + "\n"; } diff --git a/regression-tests/test-results/version b/regression-tests/test-results/version index 0cdff8201..093c5845e 100644 --- a/regression-tests/test-results/version +++ b/regression-tests/test-results/version @@ -1,5 +1,5 @@ -cppfront compiler v0.2.1 Build 8814:1300 +cppfront compiler v0.2.1 Build 8815:1647 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 fe227e212..33696210b 100644 --- a/source/build.info +++ b/source/build.info @@ -1 +1 @@ -"8814:1300" \ No newline at end of file +"8815:1647" \ No newline at end of file