User account creation filtered due to spam.

Bug 45080 - [C++0x] Rejects lambda to function pointer conversion inside function template
Summary: [C++0x] Rejects lambda to function pointer conversion inside function template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-26 14:19 UTC by Piotr Rak
Modified: 2011-05-25 15:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-05-25 05:25:26


Attachments
Test case (146 bytes, text/plain)
2010-07-26 14:21 UTC, Piotr Rak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Rak 2010-07-26 14:19:54 UTC
cat lambda-convX.C 

// { dg-options -std=c++0x }

typedef void(*pfn)();

template<int = 0>
   void f1 ()
   {
      pfn fn = []{};
   }

template<typename = int>
   void f2()
   {
      pfn fn = []{};
   }
   
void test()
{
    f1<>();
    f2<>();
}
[prak@a tmp] g++-trunk -v lambda-convX.C -c -std=c++0x
Using built-in specs.
COLLECT_GCC=/home/prak/Dev/gcc-install/bin/g++-trunk
COLLECT_LTO_WRAPPER=/home/prak/Dev/gcc-install/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc.git/configure --enable-languages=c,c++ --program-suffix=-trunk --prefix=/home/prak/Dev/gcc-install --disable-bootstrap : (reconfigured) ../gcc.git/configure --enable-languages=c,c++ --program-suffix=-trunk --prefix=/home/prak/Dev/gcc-install --disable-bootstrap : (reconfigured) ../gcc.git/configure --program-suffix=-trunk --prefix=/home/prak/Dev/gcc-install --disable-bootstrap --enable-languages=c,c++,lto --no-create --no-recursion
Thread model: posix
gcc version 4.6.0 20100725 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-c' '-std=c++0x' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
 /home/prak/Dev/gcc-install/libexec/gcc/i686-pc-linux-gnu/4.6.0/cc1plus -quiet -v -D_GNU_SOURCE lambda-convX.C -quiet -dumpbase lambda-convX.C -mtune=generic -march=pentiumpro -auxbase lambda-convX -std=c++0x -version -o /tmp/ccwd0zJD.s
GNU C++ (GCC) version 4.6.0 20100725 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 4.4.4, GMP version 4.3.2, MPFR version 3.0.0, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/../../../../include/c++/4.6.0
 /home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/../../../../include/c++/4.6.0/i686-pc-linux-gnu
 /home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/../../../../include/c++/4.6.0/backward
 /home/prak/Dev/gcc-install/include
 /home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/include
 /home/prak/Dev/gcc-install/lib/gcc/i686-pc-linux-gnu/4.6.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.6.0 20100725 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 4.4.4, GMP version 4.3.2, MPFR version 3.0.0, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4866727cef69d58d8539d96f2ebb2a27
lambda-convX.C: In function ‘void f1() [with int <anonymous> = 0]’:
lambda-convX.C:20:10:   instantiated from here
lambda-convX.C:9:19: error: cannot convert ‘f1() [with int <anonymous> = 0]::<lambda()>’ to ‘pfn’ in initialization
lambda-convX.C: In function ‘void f2() [with <template-parameter-1-1> = int]’:
lambda-convX.C:21:10:   instantiated from here
lambda-convX.C:15:19: error: cannot convert ‘f2() [with <template-parameter-1-1> = int]::<lambda()>’ to ‘pfn’ in initialization
Comment 1 Piotr Rak 2010-07-26 14:21:07 UTC
Created attachment 21316 [details]
Test case
Comment 2 Jason Merrill 2011-05-25 14:35:03 UTC
Author: jason
Date: Wed May 25 14:35:00 2011
New Revision: 174203

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174203
Log:
	PR c++/45080
	* pt.c (instantiate_class_template_1): Call maybe_add_lambda_conv_op.
	* semantics.c (lambda_function): Check COMPLETE_OR_OPEN_TYPE_P.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-05-25 15:26:29 UTC
Author: jason
Date: Wed May 25 15:26:25 2011
New Revision: 174208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174208
Log:
	PR c++/45080
	* pt.c (instantiate_class_template_1): Call maybe_add_lambda_conv_op.
	* semantics.c (lambda_function): Check COMPLETE_OR_OPEN_TYPE_P.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv5.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/pt.c
    branches/gcc-4_6-branch/gcc/cp/semantics.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2011-05-25 15:28:57 UTC
Fixed for 4.6.1.