A
Alf P. Steinbach
<code>
#include <memory>
using namespace std;
struct T {};
T* foo() { return new T; }
T const* bar() { return foo(); }
int main()
{
unique_ptr< T const > p1( bar() ); // OK
unique_ptr< T const [] > a1( bar() ); // OK
unique_ptr< T const > p2( foo() ); // OK
unique_ptr< T const [] > a2( foo() ); // ? this is line #15
}
</code>
Example errors with Visual C++ 10.0 and MinGW g++ 4.4.1:
foo.cpp(15) : error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot
access private member declared in class 'std::uni
que_ptr<_Ty>'
with
[
_Ty=const T []
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\memory(2509) : see declaration of 'std::unique_pt
r<_Ty>::unique_ptr'
with
[
_Ty=const T []
]
[d:\dev\test]
(x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/unique_ptr.h:
In function 'int mai
n()':
c:\program files
(x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/unique_ptr.h:379:
error: deleted f
foo.cpp:15: error: used here
[d:\dev\test]
It seems to me that the array version should accept the same implicit
const-adding as the non-array version.
The difference is that the array version should not accept pointer to a
derived class, and that's the machinery that apparently kicks in above.
Is the code valid?
If the code is formally invalid, does the standard's wording reflect the
intent (i.e., is a DR appropriate)?
If no to the first and yes to the second, is the intent defective (i.e.,
again, is a DR appropriate)?
Cheers,
- Alf
#include <memory>
using namespace std;
struct T {};
T* foo() { return new T; }
T const* bar() { return foo(); }
int main()
{
unique_ptr< T const > p1( bar() ); // OK
unique_ptr< T const [] > a1( bar() ); // OK
unique_ptr< T const > p2( foo() ); // OK
unique_ptr< T const [] > a2( foo() ); // ? this is line #15
}
</code>
Example errors with Visual C++ 10.0 and MinGW g++ 4.4.1:
foo.cppcl foo.cpp
foo.cpp(15) : error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot
access private member declared in class 'std::uni
que_ptr<_Ty>'
with
[
_Ty=const T []
]
C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\INCLUDE\memory(2509) : see declaration of 'std::unique_pt
r<_Ty>::unique_ptr'
with
[
_Ty=const T []
]
[d:\dev\test]
c:\program filesg++ foo.cpp -std=c++0x
(x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/unique_ptr.h:
In function 'int mai
n()':
c:\program files
(x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/unique_ptr.h:379:
error: deleted f
std::default_delete<const T []>]'unction 'std::unique_ptr said:::type*) [with _Up = T, _Tp = const T, _Tp_Deleter =
foo.cpp:15: error: used here
[d:\dev\test]
</example>
It seems to me that the array version should accept the same implicit
const-adding as the non-array version.
The difference is that the array version should not accept pointer to a
derived class, and that's the machinery that apparently kicks in above.
Is the code valid?
If the code is formally invalid, does the standard's wording reflect the
intent (i.e., is a DR appropriate)?
If no to the first and yes to the second, is the intent defective (i.e.,
again, is a DR appropriate)?
Cheers,
- Alf