Bug 98163 - ICE symtab_node::verify failed, auto& NTTP specialized with same entity but different type.
Summary: ICE symtab_node::verify failed, auto& NTTP specialized with same entity but d...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure, ice-checking, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-12-06 14:31 UTC by Lénárd Szolnoki
Modified: 2025-09-03 16:08 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-12-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lénárd Szolnoki 2020-12-06 14:31:12 UTC
g++ (Compiler-Explorer-Build) 11.0.0 20201205 (experimental)

command line flags: -std=c++17 -pedantic-errors

```
template <auto& ref>
struct S {};

template <typename T>
void foo(T) {}

extern const int arr[];

// arr is const int[]
void bar(S<arr> s) {
    foo(s);
}

const int arr[2] = {1,2};

// arr is const int[2]
void baz(S<arr> s) {
    foo(s);
}
```

source>:19:1: error: Two symbols with same comdat_group are not linked by the same_comdat_group list.
   19 | }
      | ^
_Z3fooI1SIL_Z3arrEEEvT_/4 (void foo(T) [with T = S<arr>]) @0x7f7216d81330
  Type: function definition analyzed
  Visibility: no_reorder public weak comdat comdat_group:_Z3fooI1SIL_Z3arrEEEvT_ one_only
  previous sharing asm name: 3
  References: 
  Referring: 
  Function flags: body
  Called by: _Z3baz1SIL_Z3arrEE/2 
  Calls: 
_Z3fooI1SIL_Z3arrEEEvT_/3 (void foo(T) [with T = S<arr>]) @0x7f7216d81220
  Type: function definition analyzed
  Visibility: no_reorder public weak comdat comdat_group:_Z3fooI1SIL_Z3arrEEEvT_ one_only
  next sharing asm name: 4
  References: 
  Referring: 
  Function flags: body
  Called by: _Z3bar1SIL_Z3arrEE/0 
  Calls: 
<source>:19:1: internal compiler error: symtab_node::verify failed
0x1c39f09 internal_error(char const*, ...)
	???:0
0xacca22 symtab_node::verify_symtab_nodes()
	???:0
0xae8def 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

godbolt: https://godbolt.org/z/bKc1c1
Comment 1 Marek Polacek 2020-12-07 04:13:48 UTC
Probably a dup of bug 91241.
Comment 2 Martin Liška 2020-12-07 10:23:57 UTC
This one started with r7-4431-g4a826ca6feb3c7ec, it was rejected before that:

pr98163.C:1:17: error: ‘auto’ parameter not permitted in this context
 template <auto& ref>
                 ^~~
pr98163.C:10:15: note: invalid template non-type parameter
 void bar(S<arr> s) {
               ^
pr98163.C:17:15: note: invalid template non-type parameter
 void baz(S<arr> s) {
               ^
Comment 3 Martin Liška 2020-12-07 10:26:01 UTC
and without the checking one gets an assembler error:

$ g++ pr98163.C -c -std=c++17 -pedantic-errors
/tmp/cclBTXg2.s: Assembler messages:
/tmp/cclBTXg2.s:70: Error: symbol `_Z3fooI1SIL_Z3arrEEEvT_' is already defined

so the checking really makes sense.
Comment 4 Lénárd Szolnoki 2020-12-07 21:22:25 UTC
Other example in the same spirit, but not using array of unknown bound:

```
template <auto&>
struct S {};

template <typename T>
void foo(T) {}

int i;
constexpr const int& iref = i;

template void foo(S<i>);
template void foo(S<iref>);
```
Comment 5 Johannes Larsen 2025-09-03 16:08:21 UTC
Another similar example:
```
struct foo {
};
static constexpr const foo obj{};

template <class T, const foo& OBJ>
struct wrapper{
};

wrapper<foo, obj>
returned() {
    return {};
}

template <class T, const foo& OBJ>
constexpr inline void
f(wrapper<T, OBJ>)
{
}

int main() {
    f<foo, obj>({});
    f(returned());
    return 0;
}
```

This fails on GCC 14.1 and upwards with assembler error, and with ICE when checking is enabled up to GCC 14.2:

```

Executor x86-64 gcc 14.2 (C++, Editor #1)

x86-64 gcc 14.2
x86-64 gcc 14.2
Compiler options for execution
-pedantic-errors -fchecking
Execution arguments...
Could not execute the program
Build failed
Compiler returned: 1
Compiler stderr
<source>:24:1: error: Two symbols with same comdat_group are not linked by the same_comdat_group list.
   24 | }
      | ^
_Z1fI3fooL_ZL3objEEv7wrapperIT_XT0_EE/4 (constexpr void f(wrapper<T, OBJ>) [with T = foo; const foo& OBJ = (& obj)])
  Type: function definition analyzed
  Visibility: semantic_interposition no_reorder public weak comdat comdat_group:_Z1fI3fooL_ZL3objEEv7wrapperIT_XT0_EE one_only
  previous sharing asm name: 3
  References: 
  Referring: 
  Function flags: body
  Called by: main/2 
  Calls: 
_Z1fI3fooL_ZL3objEEv7wrapperIT_XT0_EE/3 (constexpr void f(wrapper<T, OBJ>) [with T = foo; const foo& OBJ = obj])
  Type: function definition analyzed
  Visibility: semantic_interposition no_reorder public weak comdat comdat_group:_Z1fI3fooL_ZL3objEEv7wrapperIT_XT0_EE one_only
  next sharing asm name: 4
  References: 
  Referring: 
  Function flags: body
  Called by: main/2 
  Calls: 
<source>:24: confused by earlier errors, bailing out
```