Bug 59949 - lambda expression as default argument of function template causes "already defined" messages in assembler
Summary: lambda expression as default argument of function template causes "already de...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure, c++-lambda
: 65870 78919 (view as bug list)
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2014-01-26 11:56 UTC by Moritz Bunkus
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-10-22 00:00:00


Attachments
sample file causing the bug (192 bytes, text/x-csrc)
2014-01-26 11:56 UTC, Moritz Bunkus
Details
compiler output with g++ 4.8.2 (507 bytes, text/plain)
2014-01-26 11:57 UTC, Moritz Bunkus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Moritz Bunkus 2014-01-26 11:56:54 UTC
Created attachment 31954 [details]
sample file causing the bug

I have a template function that takes an std::function argument. This argument has a default value, an in-place declared lambda function. As soon as I use that template function more than once with different types within a compilation unit I receive error messages from the assembler about symbols that are defined already.

I've distilled it down to a code snippet I'm going to attach. In the original code the lambda function was actually using the template parameter T and could therefore not be converted to standalone function.

This fails with 4.8 and 4.8.2, but I remember it failing back as early as 4.6.3.

It works nicely with clang++ 3.3 and 3.4. With »works nicely« I mean that it compiles cleanly, links, and the resulting code does what I want it to (in my original source; this sample code obviously doesn't do anything at all).

The command line used:

g++ -std=c++11 -o cpp1 cpp1.cpp
Comment 1 Moritz Bunkus 2014-01-26 11:57:26 UTC
Created attachment 31955 [details]
compiler output with g++ 4.8.2
Comment 2 Jonathan Wakely 2014-01-26 13:57:44 UTC
The problem is unrelated to std::function:

struct A
{
  template<typename T> A(T) { }
};

template<typename T>
void
stuff(A = []{ }) {
}

int main() {
  stuff<int>();
  stuff<unsigned int>();
}
Comment 3 Jonas Jelten 2017-08-17 16:03:20 UTC
This bug is still present in g++ 6.4.0.
Comment 4 paolo@gcc.gnu.org 2017-09-13 11:58:28 UTC
Author: paolo
Date: Wed Sep 13 11:57:56 2017
New Revision: 252079

URL: https://gcc.gnu.org/viewcvs?rev=252079&root=gcc&view=rev
Log:
2017-09-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59949
	* g++.dg/cpp0x/lambda/lambda-defarg7.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg7.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 5 Paolo Carlini 2017-09-13 11:59:04 UTC
Fixed in trunk.
Comment 6 Paolo Carlini 2017-09-30 19:48:58 UTC
*** Bug 65870 has been marked as a duplicate of this bug. ***
Comment 7 Paolo Carlini 2017-09-30 21:07:51 UTC
*** Bug 78919 has been marked as a duplicate of this bug. ***