On Mon, Jun 5, 2017 at 6:55 AM, Volker Reichelt <v.reich...@netcologne.de> wrote: > On 15 May, Martin Sebor wrote: >>> So how about the following then? I stayed with the catch part and added >>> a parameter to the warning to let the user decide on the warnings she/he >>> wants to get: -Wcatch-value=n. >>> -Wcatch-value=1 only warns for polymorphic classes that are caught by >>> value (to avoid slicing), -Wcatch-value=2 warns for all classes that >>> are caught by value (to avoid copies). And finally -Wcatch-value=3 >>> warns for everything not caught by reference to find typos (like pointer >>> instead of reference) and bad coding practices. >> >> It seems reasonable to me. I'm not too fond of multi-level >> warnings since few users take advantage of anything but the >> default, but this case is simple and innocuous enough that >> I don't think it can do harm. >> >>> >>> Bootstrapped and regtested on x86_64-pc-linux-gnu. >>> OK for trunk? >>> >>> If so, would it make sense to add -Wcatch-value=1 to -Wextra or even -Wall? >>> I would do this in a seperate patch, becuase I haven't checked what that >>> would mean for the testsuite. >> >> I can't think of a use case for polymorphic slicing that's not >> harmful so unless there is a common one that escapes me, I'd say >> -Wall. > > So that's what I committed after Jason's OK. > >> What are your thoughts on enhancing the warning to also handle >> the rethrow case? >> >> Also, it seems that a similar warning would be useful even beyond >> catch handlers, to help detect slicing when passing arguments to >> functions by value. Especially in code that mixes OOP with the >> STL (or other template libraries). Have you thought about tackling >> that at some point as well? > > I don't have any plans to handle handle the rethrow case. > > A general slicing warning would be very nice to have. Actually > clang-tidy has one (which is a little buggy, though). > Implementing this is over my head, though. > I'd rather stick with something less ambitious.
FWIW I think it would be pretty straightforward to do this in convert_like_real, under the ck_base case. Jason