Search

T const & が char[]を受け取れない / T const & cannot receive char[] by はぴぴ

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 724314
Opened: 2/9/2012 6:37:23 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
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 (&)[]?
Details (expand)

Visual Studio/Team Foundation Server/.NET Frameworkツール製品名

Visual Studio 2010 SP1

再現手順

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[]){

//1 番目の引数を 'char []' から '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";

製品言語

Japanese

オペレーティング システム

Windows XP

オペレーティング システム言語

Japanese

実際の結果

C2664: 1 番目の引数を 'char []' から 'char const (&)[1]' に変換できません
C2664: cannot convert 1st argument from char [] to char const (&)[1]

期待した結果

char [] が char *const & または char const (&)[] に暗黙に変換される
char [] is converted to char *const or char const (&)[] implicitly
File Attachments
0 attachments
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
Hello,

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.

Thanks,
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)
Sign in to post a workaround.