https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120635
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:3f14efbe47b0607ca9c0fac6de7345733b084be6 commit r17-2362-g3f14efbe47b0607ca9c0fac6de7345733b084be6 Author: Jakub Jelinek <[email protected]> Date: Mon Jul 13 18:33:37 2026 +0200 c++: Implement clang::no_specializations attribute and -Winvalid-specialization warning [PR120635] The following patch implements the clang::no_specializations attribute (in all of [[clang::no_specializations]] [[clang::no_specializations ("reason")]] __attribute__((no_specializations)) __attribute__((no_specializations ("reason"))) forms), which can appertain to class, variable and function templates (though, not to their specializations), and if the attribute is present on the template, there is an error (that is what clang++ implements, not warning) if one attempts to partially or fully specialize it. The error can be disabled either with -Wno-invalid-specialization on the command line or #pragma GCC diagnostic ignored "-Winvalid-specialization" around the specialization or turned into warning instead of error with -Wno-error=invalid-specialization. This is intended mainly for libstdc++, so that it can diagnose various nits in the standard like https://cplusplus.github.io/LWG/issue3990 etc. 2026-07-13 Jakub Jelinek <[email protected]> PR c++/120635 gcc/ * doc/extend.texi (no_specializations): Document new attribute. * doc/invoke.texi (-Wno-invalid-specialization): Document new warning. gcc/c-family/ * c.opt (Winvalid-specialization): New option. * c.opt.urls: Regenerate. * c-lex.cc (c_common_has_attribute): Don't advertise gnu::no_specializations attribute availability. gcc/cp/ * tree.cc (cxx_gnu_attributes): Add "no_specializations" entry. (cxx_clang_attributes): Likewise. (handle_no_specializations_attribute, handle_gnu_no_specializations_attribute): New functions. * decl2.cc (is_late_template_attribute): Return false for "no_specializations" attribute, even on dependent types. Don't differentiate between the completely unknown and dependent cases, for the 5 template attributes return always false, for others true if dependent type and false otherwise. * parser.cc (cp_parser_std_attribute): Use uneval_string_attr even for clang::no_specializations attribute. * pt.cc: Include "escaped_string.h". (maybe_diagnose_no_specializations): New function. (maybe_process_partial_specialization): Use it. (check_explicit_specialization): Likewise. gcc/testsuite/ * g++.dg/ext/attr-no_specializations1.C: New test. * g++.dg/ext/attr-no_specializations2.C: New test. * g++.dg/ext/attr-no_specializations3.C: New test. * g++.dg/ext/attr-no_specializations4.C: New test. * g++.dg/ext/attr-no_specializations5.C: New test. * g++.dg/ext/attr-no_specializations6.C: New test. * g++.dg/ext/attr-no_specializations7.C: New test. * g++.dg/ext/attr-no_specializations8.C: New test. * g++.dg/ext/attr-no_specializations9.C: New test. * g++.dg/ext/attr-no_specializations10.C: New test. * g++.dg/ext/attr-no_specializations11.C: New test. Reviewed-by: Jason Merrill <[email protected]>
