On Fri, 18 Nov 2022 11:06:29 -0500 Jason Merrill <ja...@redhat.com> wrote:
> Ah, so the problem is deferred parsing of methods, rather than > templates. Building the DECL_RESULT sooner does seem like the right > approach to handling that, whether that's in grokfndecl or grokmethod. > >> I'd like to get the template case right while we're looking at it. I > >> guess I can add that myself if you're done trying. Please do, i'd be glad if you could take care of these locations. It icks me that they are wrong, and be it just for the sake of QOI :) > >>> Is the hunk for normal functions OK for trunk? > >> > >> You also need a testcase for the desired behavior, with e.g. > >> { dg-error "23:" } > > > > I'd have to think about how to test that with trunk, yes. > > There are no existing warnings that want to point to the return type, > > are there? > > Good point. Do any of your later patches add such a warning? I didn't mean to have that -Wtype-demotion applied in it's current form, or at all, so no. I was curious if anybody liked the idea of pointing out such code though. I've had no feedback but everybody is or was busy with end of stage3 and real work, so that's expected. The only real purpose i had for it was to find places in the Fortran FE that could use narrower types, bools for the most part. IMHO it would be a nice thing to have, but then, embedded software usually is cautious to use sensible types in the first place and the rest doesn't really care anyway, supposedly. Maybe it would have made more sense to just do an IPA pass that does the demotion silently where it's feasable. As to the test, i don't think these locations in the c++ FE are changed all that often, so chances are rather low that they would be broken once in. So, short of trying to use the result decl locus for any existing -Wreturn-type, -Waggregate-return, -Wno-return-local-addr, -Wsuggest-attribute=[pure|const|noreturn|format|malloc] or another existing warning that would be concerned, we could, as said, have a plugin with fix-it hints and ideally -fdiagnostics-generate-patch to test these bits. Patch generation has the advantage that it will ICE more often than not if asked to generate patches for locations that have a negative relative start (think: memcpy(...,..., -7)), which you can get easily if the locations are off IMHO. > > Maybe a g++.dg/plugin/result_decl_plugin.c then.