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

Nicola Gigante nicola.gigante at gmail.com
Mon Apr 21 03:33:06 PDT 2014


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



More information about the cfe-dev mailing list