decltype がサイズが 0 の配列への参照を作れる / decltype can generate references of zero sized array - by はぴぴ

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 724319 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/9/2012 7:37:17 PM
Access Restriction Public

Description

Visual C++ 2010 Expressを使用しています。
I use Visual C++ 2010 Express.

typedef char A[];
typedef A &RA;

上記は C2265: サイズが 0 の配列への参照は無効です というエラーが発生します。
Above code raise an error, C2265: reference of zero sized array is invalid.

extern char a[];
typedef decltype((a)) RA2;

上記は、エラーが発生せず char (&)[] という型を作ることができます。
Above code can generate the type - char (&)[] without errors.

char (&)[] という型は内部的には可能であることを示唆しています。
It suggests the type - char (&)[] can be generated internally.

https://connect.microsoft.com/VisualStudio/feedback/details/724314/t-const-char-t-const-cannot-receive-char

上記のURLで char[] が T const & に変換できない問題を挙げましたが、現在では decltype を1つの回避策として使用しています。
In above URL, I give the problem - T const & cannot receive char[], currently I am using decltype as an alternative method.

しかし、この方法は、char [] 型の変数を宣言する必要があるため、任意の型 T に対する T const (&)[] を作れません。
But this way cannot generate T const (&)[] - T is any type, because decleration of char [] type variable is needed.

やはり、T (&)[] という型を decltype なしで宣言できる必用があると思います。
Then the type - T (&)[] should be declared without decltype.
Sign in to post a comment.
Posted by はぴぴ on 2/26/2012 at 6:49 PM
Thank you for reacting.
Posted by Microsoft on 2/23/2012 at 3:52 PM
Hello,

Thank you for reporting these issues. C2265 is no longer given on that line, we've added functionality to compiler to allow references to zero-length array. However, that last error message on calling f2(a) is not a legal C++ code. Compiler cannot deduce T in the function parameter type from the argument list. Please explicitly define the argument correctly on calling f2().

Thanks,
Ulzii Luvsanbat
Visual C++ Team
Posted by Microsoft on 2/20/2012 at 1:32 AM
この度はフィードバックをお送りいただき、誠にありがとうございます。 現在、お送りいただきました報告内容に基づき問題を確認中ですので、しばらくお待ちください。 よろしくお願いいたします。

[Problem Description]:
I use Visual C++ 2010 Express. typedef char A[]; typedef A &RA; The above returns an error message C2265: reference of array which size is zero is invalid. extern char a[]; typedef decltype((a)) RA2; The above can create type char (&)[] without generating an error. This suggests that it is possible to internally create the type char (&)[]. https://connect.microsoft.com/VisualStudio/feedback/details/724314/t-const-char-t-const-cannot-receive-char In the above URL, I mentioned the problem: char[] cannot be converted to T const &. I use decltype as one of detouring tool. However, because this tool requires declaration of variable of type char [], T const (&)[] for a custom type T cannot be created. Therefore I believe that declaration of type T (&)[] without decltype is still necessary.

[Repro Steps]:
extern char a[];
typedef char A[];
//reference to zero-sized array is invalid
//reference of array which size is zero is invalid
typedef A &RA; //C2265
//decltype can generate reference of array which size is zero?
typedef decltype((a)) RA2; //ok: char(&)[]
char *b = "b";
char c[] = "c";
template<typename T>
void f(T const &){}
void f(RA2){}
//reference to zero-sized array is invalid
//reference of array which size is zero is invalid
template<typename T>
void f(T const (&)[]{} //C2265
template<typename T>
struct zero_array_ref{
static T dummy[];
typedef decltype((dummy)) type;
};
//can define, but cannot specify
//can define, but cannot specify
template<typename T>
void f2(typename zero_array_ref<T>::type){}

int main(int argc, char *argv[]){
f(a); //ok: f(RA2) is called
f(b); //ok: f(T const &) is called
f(c); //ok: f(T const &) is called
f(argv[0]); //ok: f(T const &) is called. argv[0] is not char[] but char*
//cannot reduce template arguments against 'T'
//cannot reduce template arguments against T
f2(a); //C2783
}
char a[] = "a";

[Actual Results]:
char (&)[] can only be declared with decltype
'T (&)[]' cannot be declared
char (&)[] can be declared with only decltype
T (&)[] cannot be declared

[Expected Results]:
Both char (&)[] and T (&)[] can be declared without decltype
char (&)[] and T (&)[] can be declared widhout decltype
char (&)[] can only be declared with 'decltype'
T (&)[] cannot be declared
char (&)[] can be declared with only decltype
T (&)[] cannot be declared
Both char (&)[] and T (&)[] can be declared without decltype
char (&)[] and T (&)[] can be declared widhout decltype
Posted by Microsoft on 2/10/2012 at 1:16 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)