https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119838
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:2ca183c113effe2d334b2227f4fdfa5666db8874 commit r16-2146-g2ca183c113effe2d334b2227f4fdfa5666db8874 Author: Marek Polacek <pola...@redhat.com> Date: Tue Jul 8 14:36:37 2025 -0400 c++: optional template after :: causing error [PR119838] Found while working on Reflection where we currently reject: constexpr auto r = ^^::template C<int>::type; which should work, because "::template C<int>::" should match the nested-name-specifier template(opt) simple-template-id :: production where the template is optional. This bug is not limited to Reflection as demonstrated by the attached test case, so I'm submitting it separately. The check_template_keyword_in_nested_name_spec call should ensure that we're dealing with a template-id if we've seen "template". PR c++/119838 gcc/cp/ChangeLog: * parser.cc (cp_parser_nested_name_specifier_opt): New global_p parameter. Look for "template" when global_p is true. (cp_parser_simple_type_specifier): Pass global_p to cp_parser_nested_name_specifier_opt. gcc/testsuite/ChangeLog: * g++.dg/parse/template32.C: New test. Reviewed-by: Jason Merrill <ja...@redhat.com>