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

            Bug ID: 103937
           Summary: Assembler error: symbol is already defined when
                    compiling static member function templates
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mac.zyg2 at protonmail dot com
  Target Milestone: ---

Created attachment 52139
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52139&action=edit
Full error message for GCC 11.2

This code doesn't compile with "symbol ... is already defined":
```
class SortAlgorithm {
public:
    template<typename T>
    static void test(T* t, bool(*compare_func)() = 
                    []() -> bool { return true; }) {
        test(t);
    }
};

int main() {
    int arr[] { 1, 2 };
    SortAlgorithm::test(arr);
}
```

The names that are included in the error demangles to this:

```
>>> demangle('_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_clEv')
'SortAlgorithm::test<int>(int*, bool (*)())::{default
arg#1}::{lambda()#1}::operator()() const'
>>> demangle('_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NUlvE_4_FUNEv')
'SortAlgorithm::test<int>(int*, bool (*)())::{default
arg#1}::{lambda()#1}::_FUN()'
>>> demangle('_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_cvS4_Ev')
'SortAlgorithm::test<int>(int*, bool (*)())::{default
arg#1}::{lambda()#1}::operator bool (*)()() const'
```

This code throws internal compiler error on trunk:

```
<source>:13:1: error: Two symbols with same comdat_group are not linked by the
same_comdat_group list.
   13 | }
      | ^
_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_cvS4_Ev/6 (constexpr
SortAlgorithm::<lambda()>::operator bool (*)()() const) @0x7f86cadb8880
  Type: function definition analyzed
  Visibility: semantic_interposition no_reorder public weak comdat
comdat_group:_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_cvS4_Ev one_only
artificial
  previous sharing asm name: 2
  References: _ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NUlvE_4_FUNEv/5 (addr)
__gxx_personality_v0/8 (addr) 
  Referring: 
  Function flags: body
  Called by: _ZN13SortAlgorithm4testIiEEvPT_PFbvE/7 
  Calls: 
_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_cvS4_Ev/2 (constexpr
SortAlgorithm::<lambda()>::operator bool (*)()() const) @0x7f86cadb8440
  Type: function definition analyzed
  Visibility: semantic_interposition no_reorder public weak comdat
comdat_group:_ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NKUlvE_cvS4_Ev one_only
artificial
  next sharing asm name: 6
  References: _ZZN13SortAlgorithm4testIiEEvPT_PFbvEEd_NUlvE_4_FUNEv/1 (addr)
__gxx_personality_v0/8 (addr) 
  Referring: 
  Function flags: body
  Called by: main/3 
  Calls: 
<source>:13:1: internal compiler error: symtab_node::verify failed
0x213d2c9 internal_error(char const*, ...)
        ???:0
0xbd4532 symtab_node::verify_symtab_nodes()
        ???:0
0xbf0a6f symbol_table::finalize_compilation_unit()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

Demo: https://godbolt.org/z/G796Wxehb

Reply via email to