T const & が char[]を受け取れない / T const & cannot receive char[] - 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.

Sign in
to vote
ID 724314 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/9/2012 6:37:23 PM
Access Restriction Public


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

どのような引数の参照でも受け取れる関数 template<typename T> f(T const &) を作ろうとしていた所、サイズが0または未定の配列である、char [] 型の変数を受け取れないことがわかりました。
When I make a function "template<typename T> f(T const &)" which can recieve any reference of argument, I notice it cannot recieve a variable of 0 size array / pending size array - char [].

char [] が char * に暗黙にキャストされ、char * が char *const & に暗黙にキャストされて f(T const &) に渡されると意図しました。
I intend to convert char [] to char * implicitly, and to convert char * to char *const & implicitly.

しかし、なぜか、char [] は char const (&)[1] への変換が試みられたようです。
But, char [] was tried to convert char const (&)[1] somehow.

char *const & または char const (&)[] のどちらかに暗黙に変換されるべきではないでしょうか?
Should it be converted to char *const & or char const (&)[]?
Sign in to post a comment.
Posted by はぴぴ on 2/26/2012 at 6:48 PM
Thank you for your reacting.
Posted by Microsoft on 2/23/2012 at 3:39 PM

Thank you for reporting this bug. This indeed was a compiler bug in VS2010 in doing parameter conversions related template argument deductions. We have fixed the bug now, next major release of VS will have the problem solved.

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

[Problem Description]:
I use Visual C++ 2010 Express. While I attempted to make function template f(T const &) that can receive reference of any argument, I found that it cannot receive variables of char [] type, which has size of 0 or unscheduled arrangement. I intended char [] to be tacitly converted to char * and then char * to be tacitly converted to char *const & and then passed to f(T const &). However, somehow it seems that an attempt was made to convert char [] to char const (&)[1]. Shouldn't it be converted to either char *const & or char const (&)[] tacitly?

[Repro Steps:]
extern char a[];
struct A{
char a[];
} d;
char *b = "b";
char c[] = "c";
template<typename T>
void f(T const &){}
int main(int argc, char *argv[]){
// cannot convert 1st argument from 'char []' to 'char const (&)[1]'
//cannot convert 1st argument from char [] to char const (&)[1]
f(a); //C2664
f(d.a); //C2664
f(b); //ok
f(c); //ok
f(argv[0]); //ok: argv[0] is not char [] but char*
char a[] = "a";
[Actual Results]:
C2664: Cannot convert 1st argument from 'char []' to 'char const (&)[1].'

[Expected Results]:
char [' converted to char *const & or char const (&)[] tacitly.

C2664: Cannot convert 1st argument from 'char []' to 'char const (&)[1]'
char [] converted to char const & or char const (&)[] tacitly.
Posted by Microsoft on 2/10/2012 at 1:21 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)