Re: GCC behave different for cv-qualifier function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14 December 2010 09:11, Jonathan Wakely wrote:
> On 14 December 2010 07:26, zhang qingshan wrote:
>> std 8.3.2/1 says
>>
>> Cv-qualified references are ill-formed except when the cv-qualifiers
>> are introduced through
>> the use of a typedef (7.1.3) or of a template type argument (14.3), in
>> which case the cv-qualifiers are ignored
>>
>> following code is tested at GCC 4.5.0.
>>
>> template <typename T>
>> void fun(const T&t);
>> void foo();
>> void Test() {
>>  fun(foo);
>> }
>>
>> It seems that, fun should be resolved as void (void (&)()), as const
>> is ignore here.
>
> No.
>
>> However, if I try to link this problem, the link complains:
>>
>> test.cpp:(.text+0x1c): undefined reference to `void fun<void
>> ()()>(void ( const&)())'
>>
>> Why the fun here is resolved as void fun<void()()>(void ( const &)())
>> rather than void fun<void()()>(void ( &)()) ?
>
> This is the same question you asked a few days ago.  const T& is NOT a
> const-qualified reference, it is a reference to a const T.
>
> Please find a more suitable forum to learn C++ than this mailing list,
> you keep asking the same basic questions.
>

Please read these C++ FAQs, maybe they will help:

http://www.parashift.com/c++-faq/const-correctness.html#faq-18.5
http://www.parashift.com/c++-faq/const-correctness.html#faq-18.6
http://www.parashift.com/c++-faq/const-correctness.html#faq-18.7

(That last one is actually slightly incorrect, it says you should not
use "Fred & const" but actually you CANNOT use it, due to 8.3.2/1
which you quoted above)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux