Bug 107151 - Specializing a concepted template can emit bogus assembly
Summary: Specializing a concepted template can emit bogus assembly
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure
Depends on:
Blocks:
 
Reported: 2022-10-04 12:02 UTC by Alfred Agrell
Modified: 2022-10-05 09:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-10-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alfred Agrell 2022-10-04 12:02:29 UTC
#include <cstdio>
#include <concepts>

template <typename T>
void fun(T);

template <>
void fun(char c)
{
    std::puts("foo<char>()");
}

template <std::integral I>
void fun(I i)
{
    std::puts("foo<std::integral>()");
}

int main()
{
    fun<char>(' ');
}

Compile with -std=c++20.

Result:
/tmp/cctfBAWi.s: Assembler messages:
/tmp/cctfBAWi.s:63: Error: symbol `_Z3funIcEvT_' is already defined
/tmp/cctfBAWi.s: Error: .size expression for _Z3funIcEvT_ does not evaluate to a constant

Expected: Prints foo<char>(), or at least a less cryptic error. With -O2, GCC only emits one _Z3funIcEvT_, but the resulting program prints foo<std::integral>().

https://godbolt.org/z/axvdbK1Eh

Clang and MSVC have similar bugs:
https://github.com/llvm/llvm-project/issues/58142
https://developercommunity.visualstudio.com/t/Template-explicit-specializationconcept/10012835
Comment 1 Martin Liška 2022-10-05 09:05:04 UTC
Note clang rejects the code:

clang++ pr107151.C -c -std=c++20 -S
pr107151.C:14:6: error: definition with same mangled name '_Z3funIcEvT_' as another definition
void fun(I i)
     ^
pr107151.C:8:6: note: previous definition is here
void fun(char c)
     ^
1 error generated.
Comment 2 Jonathan Wakely 2022-10-05 09:10:19 UTC
I think this is PR 100825