Opened 13 years ago
Closed 12 years ago
#3909 closed Bugs (fixed)
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[], ....)
Change History (7)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Could you clarify? The type of argv you use in your example is in violation of the C++ standard, I believe.
comment:3 by , 13 years ago
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 by , 12 years ago
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:7 by , 12 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
I assume this is fixed by earlier commits. Thanks Marshall!


Also there is a problem with constness in charT.
This causes problem: