Modify

Ticket #3909 (closed Bugs: fixed)

Opened 4 years ago

Last modified 3 years ago

parse_command_line has bad declaration

Reported by: anonymous Owned by: vladimir_prus
Milestone: Boost 1.43.0 Component: program_options
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

The parse_command_line must receive const char* const argv[].

Change:

template<class charT>
basic_parsed_options<charT>
parse_command_line(int argc, charT* 'const' argv[],
                   ....)
                  

Attachments

Change History

comment:1 Changed 4 years ago by anonymous

Also there is a problem with constness in charT.

This causes problem:

int main(int argc, char const* const argv[])
{
  parse_command_line(argc, argv);
}
  1. parse_command_line cannot receive char const* const
  2. charT = char const , there is no specialization for basic_parsed_options<char const> So there is a need to remove_cv<charT> and only then specialize basic_parsed_options.


template<class charT>
basic_parsed_options<typename remove_cv<charT>::type>
parse_command_line(int argc, charT* const argv[],
                   ....)

comment:2 Changed 4 years ago by vladimir

Could you clarify? The type of argv you use in your example is in violation of the C++ standard, I believe.

comment:3 Changed 4 years ago by anonymous

I am not sure about violation because adding const does not destroy anything. But the Standard says about int main(int argc, char* argv[]), so from this point of view you are right.

Anyway I don't know if there is a compiler which rejects main function with char const* const argv[]. Event Comeau compiler accepts it.

I suggest you to add remove_cv anyway, it will make code more correct. Thank you.

comment:4 Changed 4 years ago by ilyasokol@…

See these use cases:

 http://lists.boost.org/boost-users/2006/01/16620.php  http://lists.boost.org/boost-users/2009/08/50968.php

The signature can be changed as follows:

template<class charT>
basic_parsed_options<typename remove_cv<charT>::type>
parse_command_line(int argc, const charT* const argv[],
                   ....)

or

template<class charT>
basic_parsed_options<typename remove_cv<charT>::type>
parse_command_line(int argc, const charT* const* argv,
                   ....)

(The second is a bit more readable for me)

There is no need to remove_cv<charT> and the change is fully backward compatible.

comment:5 Changed 3 years ago by marshall

(In [66959]) Take argv as const; refs #3909

comment:6 Changed 3 years ago by marshall

(In [67006]) patch tests for Sun; refs #3909

comment:7 Changed 3 years ago by vladimir_prus

  • Status changed from new to closed
  • Resolution set to fixed

I assume this is fixed by earlier commits. Thanks Marshall!

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.