Opened 8 years ago
Closed 8 years ago
#10838 closed Bugs (fixed)
Missing std:: qualifier for strlen calls in string_ref_test2.cpp
Reported by: | Owned by: | Marshall Clow | |
---|---|---|---|
Milestone: | To Be Determined | Component: | utility |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: |
Description
Compiling with Oracle Solaris Studio on Solaris 11.2, we see
"../libs/utility/test/string_ref_test2.cpp", line 21: Error: The function "strlen" must have a prototype.
"../libs/utility/test/string_ref_test2.cpp", line 51: Error: The function "strlen" must have a prototype.
"../libs/utility/test/string_ref_test2.cpp", line 162: Error: The function "strlen" must have a prototype.
"../libs/utility/test/string_ref_test2.cpp", line 183: Error: The function "strlen" must have a prototype.
The file libs/utility/test/string_ref_test2.cpp includes <cstring>, however strlen needs to be qualified with std::
The diffs are 21c21 < const size_t sz = strlen ( arg ); ---
const size_t sz = std::strlen ( arg );
51c51 < const size_t sz = strlen ( arg ); ---
const size_t sz = std::strlen ( arg );
162c162 < p = arg + strlen ( arg ) - 1; ---
p = arg + std::strlen ( arg ) - 1;
183c183 < p = arg + strlen ( arg ) - 1; ---
p = arg + std::strlen ( arg ) - 1;
Change History (5)
comment:1 by , 8 years ago
Owner: | changed from | to
---|
comment:2 by , 8 years ago
Per the C++ standard,
D.5 C standard library headers
2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).
3 [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header <stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. —end example ]
comment:3 by , 8 years ago
In standard C++, names declared in the <cname> version of the C <name.h> headers are only in namespace std. However, gcc puts the names in the global namespace.
Line 54 of this file already qualifies strlen with std:: qualifier and as seen above, there is no error message generated for this line.
54: const char *p = arg + std::strlen ( arg ) - 1;
I have just submitted a pull request for this.
Thanks.
comment:3 by , 8 years ago
In standard C++, names declared in the <cname> version of the C <name.h> headers are only in namespace std. However, gcc puts the names in the global namespace.
Line 54 of this file already qualifies strlen with std:: qualifier and as seen above, there is no error message generated for this line.
54: const char *p = arg + std::strlen ( arg ) - 1;
I have just submitted a pull request for this.
Thanks.
comment:4 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Ok, I'm confused.
<cstring>
includes<string.h>
, which defines strlen, right?All that
<cstring>
does isusing ::strlen;
(which hoists it from the global namespace intonamespace std
)