Skip to content

Commit 11fc88d

Browse files
committed
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 !
1 parent 1570f7e commit 11fc88d

File tree

9 files changed

+10
-15
lines changed

9 files changed

+10
-15
lines changed

include/cpp2util.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1491,17 +1491,17 @@ inline auto to_string(std::tuple<Ts...> const& t) -> std::string
14911491
//
14921492
struct args_t : std::vector<std::string_view>
14931493
{
1494-
args_t(int c, char** v) : vector{static_cast<size_t>(c)}, argc{c}, argv{v}, mutable_argv{v} {}
1494+
args_t(int c, char** v) : vector{static_cast<size_t>(c)}, argc{c}, argv{v} {}
14951495

1496-
int argc = 0;
1497-
char const* const* argv = nullptr;
1498-
char** mutable_argv = nullptr;
1496+
int argc = 0;
1497+
char** argv = nullptr;
14991498
};
15001499

15011500
inline auto make_args(int argc, char** argv) -> args_t
15021501
{
1503-
auto ret = args_t{argc, argv};
1504-
std::ranges::copy( std::span(argv, argc), ret.data() );
1502+
auto ret = args_t{argc, argv};
1503+
auto args = std::span(argv, static_cast<size_t>(argc));
1504+
std::copy( args.begin(), args.end(), ret.data());
15051505
return ret;
15061506
}
15071507

regression-tests/pure2-main-args.cpp2

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ main: (args) =
22
std::cout
33
<< "args.argc is (args.argc)$\n"
44
<< "args.argv[0] is (args.argv[0])$\n"
5-
<< "args.mutable_argv[0] is (args.mutable_argv[0])$\n"
65
;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
args.argc is 1
22
args.argv[0] is ./test.exe
3-
args.mutable_argv[0] is ./test.exe
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
args.argc is 1
22
args.argv[0] is ./test.exe
3-
args.mutable_argv[0] is ./test.exe

regression-tests/test-results/gcc-13/run-tests-gcc-13.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for f in *.cpp
1010
do
1111
let count=count+1
1212
printf "[%s] Starting gcc 13 %s\n" "$count" "$f"
13-
g++ -I../../../include -std=c++20 -pthread -Wunused-parameter -o test.exe $f > $f.output 2>&1
13+
g++ -I../../../include -std=c++20 -pthread -Wold-style-cast -Wunused-parameter -o test.exe $f > $f.output 2>&1
1414
rm -f $f
1515
if test -f "test.exe"; then
1616
let exe_count=exe_count+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
args.argc is 1
22
args.argv[0] is test.exe
3-
args.mutable_argv[0] is test.exe

regression-tests/test-results/pure2-main-args.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ auto main(int const argc_, char** argv_) -> int {
2222
#line 2 "pure2-main-args.cpp2"
2323
std::cout
2424
<< "args.argc is " + cpp2::to_string(args.argc) + "\n"
25-
<< "args.argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.argv, 0)) + "\n"
26-
<< "args.mutable_argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.mutable_argv, 0)) + "\n"; }
25+
<< "args.argv[0] is " + cpp2::to_string(cpp2::assert_in_bounds(args.argv, 0)) + "\n"; }
2726

regression-tests/test-results/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8814:1300
2+
cppfront compiler v0.2.1 Build 8815:1647
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8814:1300"
1+
"8815:1647"

0 commit comments

Comments
 (0)