Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: definition with same mangled name when specializing a concepted template #58142

Closed
Alcaro opened this issue Oct 4, 2022 · 4 comments
Closed
Labels

Comments

@Alcaro
Copy link
Contributor

Alcaro commented Oct 4, 2022

#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:

<source>:14:6: error: definition with same mangled name '_Z3funIcEvT_' as another definition
<source>:8:6: note: previous definition is here

Expected: Prints foo<char>(), or at least a less cryptic error

https://godbolt.org/z/axvdbK1Eh

GCC and MSVC have similar bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107151
https://developercommunity.visualstudio.com/t/Template-explicit-specializationconcept/10012835

@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2022

@llvm/issue-subscribers-clang-codegen

@usx95 usx95 moved this to Triage Group 3 in C++ 20 in Clang Oct 14, 2022
@usx95
Copy link
Contributor

usx95 commented Oct 31, 2022

Very similar to #48216

@erichkeane
Copy link
Collaborator

erichkeane commented Nov 2, 2022

While a similar look, this isn't the same issue as #48216 has a fix for the friends instantiation, this one is unofortunately different.

@zygoloid
Copy link
Collaborator

Fixed in 4b163e3. Contrary to the suggestion at the start of this issue, the program prints

foo<std::integral>()

because the fun(char) explicit specialization specializes the primary template, not the constrained template<integral> overload, because the latter is not yet declared. And overload resolution picks the template<integral> version because it's more constrained.

@github-project-automation github-project-automation bot moved this from Triage Group 3 to Done in C++ 20 in Clang Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

6 participants