On Sun, 2 Mar 2025, xxie-xd wrote: > * Patrick Palka <ppa...@redhat.com> [2025-02-28 10:37:37]: > > > Hi, > > > > On Fri, 28 Feb 2025, Da Xie wrote: > > > > > This bug comes from a missing check when a function declaration has a > > > late-specified return type and a constrained auto type specifier. By > > > adding such a check, we can catch such uses and diagnose them as errors. > > > > > > Successfully bootstrapped and regretested on x86_64-pc-linux-gnu: > > > adds 6 new test results and 4 UNSUPPORTED results to g++.sum. The 4 > > > UNSUPPORTED results are due to the fact that concepts are not supported > > > before c++20, so tests cannot pass with c++17 and lower standards. > > > > > > PR c++/100589 > > > > > > gcc/cp/ChangeLog: > > > > > > * decl.cc (grokdeclarator): Issue an error for a declarator with > > > constrained auto type specifier and trailing return types. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * g++.dg/other/pr100589.C: New test. > > > > Thanks for the patch! Looks good to me overall, some minor comments > > below. > > > > Thank you for the review! I'll make changes to the patch based on your > advice. > > > > > > > Signed-off-by: Da Xie <xxie...@163.com> > > > --- > > > gcc/cp/decl.cc | 7 +++++++ > > > gcc/testsuite/g++.dg/other/pr100589.C | 7 +++++++ > > > 2 files changed, 14 insertions(+) > > > create mode 100644 gcc/testsuite/g++.dg/other/pr100589.C > > > > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > > > index 9ca8c6c4481..f283ed996a2 100644 > > > --- a/gcc/cp/decl.cc > > > +++ b/gcc/cp/decl.cc > > > @@ -14037,6 +14037,13 @@ grokdeclarator (const cp_declarator *declarator, > > > "invalid use of %<decltype(auto)%>"); > > > return error_mark_node; > > > } > > > + else if (is_constrained_auto (type)) > > > + { > > > + error_at (typespec_loc, "invalid use of " > > > + "constrained auto type specifier " > > > + "in function with trailing return type"); > > > > We should quote the 'auto' in this diagnostic by writing %<auto%> > > for consistency with the other diagnostics. > > > > I have added an if statement to handle cases where the declarator > represents a named function. In such scenarios, an error will be issued, > including the function name, the use of constrained %<auto%>, and the > existence of a trailing return type. For all other cases, an error > message will indicate the invalid use of constrained %<auto%>. > > Curiously, I found that if the same error message occurred multiple > times(In my case, the above error message does not print function names, > so every function/type declartions issues the same error message), > a single dg-error will catch all of them, even if these messages > are issued on different lines of code.
I believe that's actually because of the .* in your pattern, which also matches trailing newlines and so it can greedily match errors issued later in the testcase. Normally dg-error matches only errors occurring on the line it's written in. So for that reason it's better to use \[^\n\r\]* instead of .* as the "match anything" pattern in a dg-error. Very rarely do we actually want a dg-error to look into multiple lines of errors. This could use documenting on the wiki page. > I think this is the bug mentioned > in GCC Wiki (https://gcc.gnu.org/wiki/HowToPrepareATestcase#TODO). > Thankfully, in the updated testcase, the error messages are issued for a > function declaration and type declaration each. I have updated the > dg-error regex pattern to capture error messages separately for > functions and types. This ensures more precise matching and handling of > the respective error cases. > > > > + return error_mark_node; > > > + } > > > tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); > > > if (!tmpl) > > > if (tree late_auto = type_uses_auto (late_return_type)) > > > diff --git a/gcc/testsuite/g++.dg/other/pr100589.C > > > b/gcc/testsuite/g++.dg/other/pr100589.C > > > new file mode 100644 > > > index 00000000000..3fa054ed34d > > > --- /dev/null > > > +++ b/gcc/testsuite/g++.dg/other/pr100589.C > > > > Since this is a concepts-specific test let's name it > > > > g++.dg/cpp2a/concepts-pr100589.C > > > > Renamed. > > > > @@ -0,0 +1,7 @@ > > > +// PR c++/100589 > > > +// { dg-do compile { target c++20 } } > > > + > > > +template<class T> > > > +concept false_concept = false; > > > + > > > +false_concept auto f() -> int; // { dg-error "constrained auto type > > > specifier.* trailing return type" } > > > > It'd be good to also test a bare function type: > > > > using type = false_concept auto() -> int; > > > > Test added. > > > > \ No newline at end of file > > > -- > > > 2.34.1 > > > > > > > > Thanks again for your reply. I will send updated patch when the > bootstrap and regression tests are finished. > >