Skip to content

Commit

Permalink
Switched argv back to its usual standard meaning
Browse files Browse the repository at this point in the history
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 !
  • Loading branch information
hsutter committed Aug 16, 2023
1 parent 1570f7e commit 11fc88d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 15 deletions.
12 changes: 6 additions & 6 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1491,17 +1491,17 @@ inline auto to_string(std::tuple<Ts...> const& t) -> std::string
//
struct args_t : std::vector<std::string_view>
{
args_t(int c, char** v) : vector{static_cast<size_t>(c)}, argc{c}, argv{v}, mutable_argv{v} {}
args_t(int c, char** v) : vector{static_cast<size_t>(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<size_t>(argc));
std::copy( args.begin(), args.end(), ret.data());
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion regression-tests/pure2-main-args.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.mutable_argv[0] is ./test.exe
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
args.argc is 1
args.argv[0] is ./test.exe
args.mutable_argv[0] is ./test.exe
2 changes: 1 addition & 1 deletion regression-tests/test-results/gcc-13/run-tests-gcc-13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
args.argc is 1
args.argv[0] is test.exe
args.mutable_argv[0] is test.exe
3 changes: 1 addition & 2 deletions regression-tests/test-results/pure2-main-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }

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.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
Expand Down
2 changes: 1 addition & 1 deletion source/build.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"8814:1300"
"8815:1647"

0 comments on commit 11fc88d

Please sign in to comment.