Skip to content
Snippets Groups Projects
Commit cff174fa authored by Marek Polacek's avatar Marek Polacek
Browse files

c++: DR2237, cdtor and template-id tweaks [PR107126]

Since my r11-532 changes to implement DR2237, for this test:

  template<typename T>
  struct S {
    S<T>();
  };

in C++20 we emit the ugly:

q.C:3:8: error: expected unqualified-id before ')' token
    3 |   S<T>();

which doesn't explain what the problem is.  This patch improves that
diagnostic, reduces the error to a pedwarn, and adds a -Wc++20-compat
diagnostic.  We now say:

q.C:3:7: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
    3 |   S<T>();
q.C:3:7: note: remove the '< >'

This patch also fixes
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97202#c8>
where the C++20 diagnostic was missing altogether:  The problem was that I checked
for CPP_TEMPLATE_ID too early, at a point at which cp_parser_template_id may not
have been called yet.  So let's check for it at the end of the function, after
the tentative parse and rollback.

-Wc++20-compat triggered in libitm/; I sent a patch for that.

	DR 2237
	PR c++/107126
	PR c++/97202

gcc/c-family/ChangeLog:

	* c-opts.cc (c_common_post_options): In C++20 or with -Wc++20-compat,
	turn on -Wtemplate-id-cdtor.
	* c.opt (Wtemplate-id-cdtor): New.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_unqualified_id): Downgrade the DR2237 error to
	a pedwarn.
	(cp_parser_constructor_declarator_p): Likewise.

gcc/ChangeLog:

	* doc/invoke.texi: Document -Wtemplate-id-cdtor.

gcc/testsuite/ChangeLog:

	* g++.dg/DRs/dr2237.C: Adjust dg-error.
	* g++.dg/parse/constructor2.C: Likewise.
	* g++.dg/template/error34.C: Likewise.
	* g++.old-deja/g++.pt/ctor2.C: Likewise.
	* g++.dg/DRs/dr2237-2.C: New test.
	* g++.dg/DRs/dr2237-3.C: New test.
	* g++.dg/DRs/dr2237-4.C: New test.
	* g++.dg/DRs/dr2237-5.C: New test.
	* g++.dg/warn/Wtemplate-id-cdtor-1.C: New test.
	* g++.dg/warn/Wtemplate-id-cdtor-2.C: New test.
	* g++.dg/warn/Wtemplate-id-cdtor-3.C: New test.
	* g++.dg/warn/Wtemplate-id-cdtor-4.C: New test.
parent f8821933
Loading
Showing
with 146 additions and 24 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment