From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20346 invoked by alias); 18 Feb 2011 15:38:20 -0000 Received: (qmail 20234 invoked by uid 22791); 18 Feb 2011 15:38:18 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Feb 2011 15:38:13 +0000 Received: from afontenayssb-151-1-50-210.w82-121.abo.wanadoo.fr (HELO laptop-mg.local) ([82.121.91.210]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Feb 2011 16:38:10 +0100 Date: Fri, 18 Feb 2011 17:36:00 -0000 From: Marc Glisse Reply-To: gcc-help To: gcc-help cc: zhang qingshan Subject: Re: why this testcase compile failed for gcc. In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) Mail-Followup-To: gcc-help , zhang qingshan MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00289.txt.bz2 On Fri, 18 Feb 2011, Ian Lance Taylor wrote: > zhang qingshan writes: > >> /* ------- test case -------------------*/ >> void x(); >> template >> 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