https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114915
Bug ID: 114915 Summary: Constrained auto deduction in specialized template scope Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sska1377 at gmail dot com Target Milestone: --- Here is a simple code that uses constrained auto deduction in a template specialization scope. By removing the specialization, the code compiles successfully. However, with the specialization, the code fails to compile, even though both cases should be equivalent. Code: template<typename T> concept TheConcept = __is_same(T, int); template<typename T> void f() { TheConcept auto x = 1; } /* Here is the problematic function, by removing the specialization below, everything works */ template<> void f<int>() { TheConcept auto x = 1; } int main() { f<int>(); return 0; } Command: $ g++ report.cpp -std=c++20 -Wall -Wextra -save-temps Expected: Compilation success Actual: report.cpp: In function ‘void f() [with T = int]’: report.cpp:11:23: error: deduced initializer does not satisfy placeholder constraints 11 | TheConcept auto x = 1; | ^ report.cpp:11:23: note: constraints not satisfied report.cpp:2:9: required for the satisfaction of ‘TheConcept<auto [requires ::TheConcept<<placeholder>, >]>’ [with auto [requires ::TheConcept<<placeholder>, >] = auto [requires ::TheConcept<<placeholder>, >]] report.cpp:2:22: note: ‘auto [requires ::TheConcept<<placeholder>, >]’ is not the same as ‘int’ 2 | concept TheConcept = __is_same(T, int); | ^~~~~~~~~~~~~~~~~ FAIL More info: gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20240417 (GCC) --- Comment #1 from Seyed Sajad Kahani <sska1377 at gmail dot com> --- A possible fix: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/650391.html