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

clang accepts partial template specialization without base #131835

Open
abellgithub opened this issue Mar 18, 2025 · 5 comments
Open

clang accepts partial template specialization without base #131835

abellgithub opened this issue Mar 18, 2025 · 5 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" cwg-issue An issue that was filed to the Core Working Group diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue

Comments

@abellgithub
Copy link

This fails on gcc but works on clang. Note types of SYMS template arguments. I think clang is wrong here, but it could be me who's wrong ;)

#include <cstdint>
#include <type_traits>

template <int SYMS, typename T=void>
struct arithmetic_c;

template<uint32_t SYMS>
struct arithmetic_c<SYMS, typename std::enable_if<(SYMS > 16 && SYMS < 2048)>::type>
{
    arithmetic_c()
    {}
};

template<int SYMS>
struct arithmetic_c<SYMS, typename std::enable_if<(SYMS > 1 && SYMS <= 16)>::type >
{
    arithmetic_c()
    {}
};

int main()
{
    arithmetic_c<32> corrector;
    return 0;
}

Compiler Explorer

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 18, 2025
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue and removed clang Clang issues not falling into any other category labels Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/issue-subscribers-clang-frontend

Author: Andrew Bell (abellgithub)

This fails on gcc but works on clang. Note types of `SYMS` template arguments. I think clang is wrong here, but it could be me who's wrong ;)
#include &lt;cstdint&gt;
#include &lt;type_traits&gt;

template &lt;int SYMS, typename T=void&gt;
struct arithmetic_c;

template&lt;uint32_t SYMS&gt;
struct arithmetic_c&lt;SYMS, typename std::enable_if&lt;(SYMS &gt; 16 &amp;&amp; SYMS &lt; 2048)&gt;::type&gt;
{
    arithmetic_c()
    {}
};

template&lt;int SYMS&gt;
struct arithmetic_c&lt;SYMS, typename std::enable_if&lt;(SYMS &gt; 1 &amp;&amp; SYMS &lt;= 16)&gt;::type &gt;
{
    arithmetic_c()
    {}
};

int main()
{
    arithmetic_c&lt;32&gt; corrector;
    return 0;
}

Compiler Explorer

@pinskia
Copy link

pinskia commented Mar 18, 2025

@abellgithub
Copy link
Author

Yes, seems exactly the issue. Please close if you like.

@pinskia
Copy link

pinskia commented Mar 18, 2025

Yes, seems exactly the issue. Please close if you like.

Well the defect report against the C++ standard is still open. I didn't look to see if there is a different LLVM bug open referencing that defect report.

@shafik
Copy link
Collaborator

shafik commented Mar 18, 2025

gcc/edg agree and clang/MSVC agree: https://godbolt.org/z/c3j3EEn1x

@shafik shafik added diverges-from:edg Does the clang frontend diverge from edg compiler cwg-issue An issue that was filed to the Core Working Group labels Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" cwg-issue An issue that was filed to the Core Working Group diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue
Projects
None yet
Development

No branches or pull requests

5 participants