From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17316 invoked by alias); 3 Oct 2012 22:28:08 -0000 Received: (qmail 17291 invoked by uid 48); 3 Oct 2012 22:27:54 -0000 From: "matt at godbolt dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/54801] New: [c++11] static variables constructed with lambda params inside member functions cause undefined errors Date: Wed, 03 Oct 2012 22:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: matt at godbolt dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-10/txt/msg00253.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54801 Bug #: 54801 Summary: [c++11] static variables constructed with lambda params inside member functions cause undefined errors Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: matt@godbolt.org Created attachment 28346 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28346 Test C file exhibiting the issue In the attached code, there is static method with a static variable whose constructor takes a function pointer. When a lambda is passed as the function pointer, it seems the lambda's definition is dropped and the result is a link-time error. $ g++ -o test -std=c++0x test.cc /tmp/ccpBFtG7.o: In function `Test::aFunc()::{lambda(int*)#1}::operator void (*)(int*)() const': test.cc:(.text._ZZN4Test5aFuncEvENKUlPiE_cvPFvS0_EEv[_ZZN4Test5aFuncEvENKUlPiE_cvPFvS0_EEv]+0x9): undefined reference to `Test::aFunc()::{lambda(int*)#1}::_FUN(int*)' collect2: error: ld returned 1 exit status Making the variable non-static fixes the issue. The same code in a free function does not exhibit the problem. Taking a std::function as the constructor parameter also cures the issue. It seems to be something which only throws away the lambda for static variables inside member functions. More info: g++ -v Using built-in specs. COLLECT_GCC=/site/apps/gcc-4.7.2-drw.patched.1/bin/g++ COLLECT_LTO_WRAPPER=/site/apps/gcc-4.7.2-drw.patched.1/libexec/gcc/x86_64-linux-gnu/4.7.2/lto-wrapper Target: x86_64-linux-gnu Configured with: ./configure --prefix /site/apps/gcc-4.7.2-drw.patched.1 --build=x86_64-linux-gnu --enable-clocale=gnu --enable-gold --enable-languages=c,c++ --enable-ld=default --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-linker-build-id --enable-lto --enable-plugin --enable-shared --enable-threads=posix --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-pkgversion=DRW-internal-build --with-plugin-ld=ld.gold --with-system-zlib --with-gmp=/data/teamcity/work/sup-chietfbld02-002/8a981abc13d5c0c5/scratch/gcc/4.7.2/build/gmp-5.0.2 --with-mpfr=/data/teamcity/work/sup-chietfbld02-002/8a981abc13d5c0c5/scratch/gcc/4.7.2/build/mpfr-3.1.1 --with-mpc=/data/teamcity/work/sup-chietfbld02-002/8a981abc13d5c0c5/scratch/gcc/4.7.2/build/mpc-0.9 --with-libelf=/data/teamcity/work/sup-chietfbld02-002/8a981abc13d5c0c5/scratch/gcc/4.7.2/build/libelf-0.8.9 Thread model: posix gcc version 4.7.2 (DRW-internal-build) This issue was discovered when attempting to register lambda functions as the "cleanup function" for static thread-local stored information using boost::thread_specific_ptr. However, the issue is reproducible in the attached source file with no external includes. This appears to be a regression in 4.7.2: gcc versions 4.7.1, 4.7.0, 4.6.3 and 4.5.3 compile the source without issue.