From: Marc Glisse <marc.glisse@inria.fr>
To: gcc-help <gcc-help@gcc.gnu.org>
Cc: zhang qingshan <steven.zhang54373@gmail.com>
Subject: Re: why this testcase compile failed for gcc.
Date: Fri, 18 Feb 2011 17:36:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.02.1102181627120.3336@laptop-mg.saclay.inria.fr> (raw)
In-Reply-To: <mcr7hcx9ym5.fsf@google.com>
On Fri, 18 Feb 2011, Ian Lance Taylor wrote:
> zhang qingshan <steven.zhang54373@gmail.com> writes:
>
>> /* ------- test case -------------------*/
>> void x();
>> template <typename T>
>> void foo(const T*);
>>
>> int main() {
>> foo(x);
>> }
>>
>> GCC 4.5 complains:
>>
>> a.cpp: In function 'int main()':
>> a.cpp:6: error: no matching function for call to 'foo(void (&)())'
>>
>> It seems that, const T * is resolved as void (&)());
>>
>> IMO, T --> void (), const T --> void (), const T * --> void (*)(), and
>> it should be leagle.
>
> You are confusing function pointers with pointers to data objects. They
> are not the same thing in C++. That is, a function pointer is not a
> special type of pointer.
Well it still kind of is. Without the "const", the code compiles fine. But
the fact that a const qualifier on a function type is ignored seems not to
apply to template type deduction.
(note that most compilers behave like g++ here, except for clang which
accepts the original code)
--
Marc Glisse
next prev parent reply other threads:[~2011-02-18 15:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-17 7:42 zhang qingshan
2011-02-18 15:08 ` Ian Lance Taylor
2011-02-18 17:36 ` Marc Glisse [this message]
2011-02-21 6:31 ` zhang qingshan
2011-02-21 11:18 ` zhang qingshan
2011-02-21 11:28 ` Jonathan Wakely
2011-02-21 16:00 ` Ian Lance Taylor
2011-02-22 19:10 ` Andi Hellmund
2011-02-22 19:18 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.02.1102181627120.3336@laptop-mg.saclay.inria.fr \
--to=marc.glisse@inria.fr \
--cc=gcc-help@gcc.gnu.org \
--cc=steven.zhang54373@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).