https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85513

            Bug ID: 85513
           Summary: symbol already defined error if using default
                    invocable arguments with lambda expressions
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rene.r...@fu-berlin.de
  Target Milestone: ---

Created attachment 44015
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44015&action=edit
The code that produces the aformentioned error.

Hi all, I stumbled over a possible bug in the gcc compiler for the following
code:

```
#include <iterator>
#include <functional>
#include <iostream>

// DIRTY-FIX: It works, if we use this named lambda to default the callable
argument.
auto dummy = [](char){return true;};

template <typename f1,
          typename f2 = std::function<bool(char)>>  // decltype(dummy)
bool bar(f1 && _f1n,
         f2 && _f2n = [](char){return false;}) // std::move(dummy)
{
    return _f2n('c');
}

int main()
{
    auto l1 = [](char v){ return v == 'c';};
    auto l2 = [](char v){ return v == 'a';};
    std::cout << std::boolalpha << bar(l1) << '\n';
    std::cout << std::boolalpha << bar(l2) << '\n';
    return 0;
}
```

Expected Output:

false
false

Actual Output:

/tmp/ccNpZtZz.s: Assembler messages:
/tmp/ccNpZtZz.s:317: Error: symbol `_ZNKUlcE0_clEc' is already defined
/tmp/ccNpZtZz.s:588: Error: symbol
`_ZSt4moveIRUlcE0_EONSt16remove_referenceIT_E4typeEOS3_' is already defined
/tmp/ccNpZtZz.s:606: Error: symbol `_ZNSt8functionIFbcEEC2IUlcE0_vvEET_' is
already defined
/tmp/ccNpZtZz.s:922: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E21_M_not_empty_functionIS1_EEbRKT_'
is already defined
/tmp/ccNpZtZz.s:939: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E15_M_init_functorERSt9_Any_dataOS1_'
is already defined
/tmp/ccNpZtZz.s:972: Error: symbol
`_ZNSt17_Function_handlerIFbcEUlcE0_E9_M_invokeERKSt9_Any_dataOc' is already
defined
/tmp/ccNpZtZz.s:1006: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E10_M_managerERSt9_Any_dataRKS3_St18_Manager_operation'
is already defined
/tmp/ccNpZtZz.s:1224: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E15_M_init_functorERSt9_Any_dataOS1_St17integral_constantIbLb1EE'
is already defined
/tmp/ccNpZtZz.s:1252: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E14_M_get_pointerERKSt9_Any_data'
is already defined
/tmp/ccNpZtZz.s:1277: Error: symbol `_ZNSt9_Any_data9_M_accessIPUlcE0_EERT_v'
is already defined
/tmp/ccNpZtZz.s:1297: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E8_M_cloneERSt9_Any_dataRKS3_St17integral_constantIbLb1EE'
is already defined
/tmp/ccNpZtZz.s:1325: Error: symbol
`_ZNSt14_Function_base13_Base_managerIUlcE0_E10_M_destroyERSt9_Any_dataSt17integral_constantIbLb1EE'
is already defined
/tmp/ccNpZtZz.s:1406: Error: symbol `_ZNKSt9_Any_data9_M_accessIUlcE0_EERKT_v'
is already defined
/tmp/ccNpZtZz.s:1426: Error: symbol `_ZSt11__addressofIKUlcE0_EPT_RS2_' is
already defined
/tmp/ccNpZtZz.s:1444: Error: symbol `_ZNSt9_Any_data9_M_accessIUlcE0_EERT_v' is
already defined

The following compilers/systems are tested:

g++ (GCC) 7.1.0  // on debian: Linux 3.16.0-4-amd64 #1 SMP Debian
3.16.43-2+deb8u3 (2017-08-15) x86_64 GNU/Linux
g++ (Macports gcc8 8-20170604_1+universal) 8.0.0 20170604 // on mac: Darwin
Kernel Version 16.7.0

Build:

g++-7 -Wall -pedantic -O0 -std=c++17 test.cpp (test.cpp contains the code from 
above.)

Note:

The above code will work, if instead of using the anonymous lambda as a default
argument, the named lambda `dummy` would be used. Also, if in the main method
the second call to bar uses again `l1` instead of `l2` the code compiles just
fine. Also clang, does not seem to have any problems with any of the versions,
so this leaves me to the conclusion, that something is wrong with gcc?

Many thanks for your assistance.

Best,

René

Reply via email to