[cfe-dev] Doubt on a couple of warnings on deleted functions

Richard Smith richard at metafoo.co.uk
Mon Apr 21 13:57:27 PDT 2014


On 21 Apr 2014 12:43, "David Blaikie" <dblaikie at gmail.com> wrote:
>
> On Mon, Apr 21, 2014 at 11:38 AM, Richard Smith <richard at metafoo.co.uk>
wrote:
> > On Mon, Apr 21, 2014 at 7:47 AM, David Blaikie <dblaikie at gmail.com>
wrote:
> >>
> >> Yep
> >> Both of these sound like bugs and should be able to be fixed just by
> >> checking for a non-deleted definition. I'm not sure if there's a
particular
> >> function to test that.
> >
> > I think the first warning is entirely appropriate. The point of this
warning
> > is that every external linkage function should be declared in a header
file;
>
> Sure, but how would you declare the deleted function in a header file
> separate from its delete definition?
>
> What you put in the header file is "void func() = delete;" and that's
> where the warning fires, isn't it?

No, the warning fires if the first declaration of an externally visible
function is in the main source file.

> > it'd help if the warning suggested something like 'mark this function
> > 'static' if it's not intended to be used in other files' or similar.
> >>
> >> The unused variable one might crop up in defaulted functions too, in
which
> >> case we'll want to check for a user provided definition.
> >
> > I agree on both counts. The same warning is visible here:
> >
> > struct S { S(const S&s); }; S::S(const S&s) = default;
> >
> >>
> >> On Apr 21, 2014 3:35 AM, "Nicola Gigante" <nicola.gigante at gmail.com>
> >> wrote:
> >>>
> >>> Hello.
> >>>
> >>> Consider this:
> >>>
> >>> $ cat example.cpp
> >>> void func(int x) = delete;
> >>> $ clang++ -std=c++11 -fsyntax-only -Wunused-parameter
> >>> -Wmissing-prototypes example.cpp
> >>> example.cpp:1:6: warning: no previous prototype for function 'func'
> >>> [-Wmissing-prototypes]
> >>> void func(int x) = delete;
> >>>      ^
> >>> example.cpp:1:15: warning: unused parameter 'x' [-Wunused-parameter]
> >>> void func(int x) = delete;
> >>>               ^
> >>> 2 warnings generated.
> >>>
> >>> The two warnings seems false positives:
> >>>
> >>> 1) why does it warn about a missing prototype? One can't add a
prototype
> >>> because
> >>> he'll get this error:
> >>>
> >>> error: deleted definition must be first declaration
> >>> void func(int x) = delete;
> >>>
> >>> So, the deleted definition is acting like a prototype itself, doesn't
it?
> >>> I think the warning
> >>> is wrong.
> >>>
> >>> 2) Does it make sense to warn about an unused parameter on a deleted
> >>> definition?
> >>> Of course is unused, but it can't be used anyway.
> >>> This force the programmer to avoid parameters name, like:
> >>> void func(int) = delete;
> >>> but this can reduce readability and it seems to me there's no reason
to
> >>> force it.
> >>>
> >>> Note that these warnings pop up only on free functions. Deleted member
> >>> functions
> >>> don't generate these warnings in these cases.
> >>>
> >>> Does it make sense to fix these issues?
> >>>
> >>> This mail is a part of a more general effort of mine to be able to
> >>> warning-less include
> >>> (with -Weverything, more or less) the LLVM headers that I use in my
> >>> project.
> >>> I think (and hope) more will follow.
> >>>
> >>> Thanks,
> >>> Nicola
> >>> _______________________________________________
> >>> cfe-dev mailing list
> >>> cfe-dev at cs.uiuc.edu
> >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >>
> >>
> >> _______________________________________________
> >> cfe-dev mailing list
> >> cfe-dev at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >>
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140421/95ee19db/attachment.html>


More information about the cfe-dev mailing list