How do I enable a warning for unused lambda expressions in gcc?

Viewed 185

The following code has a typo, where I forgot to invoke the lambda expression with ():

#include <iostream>

int main() 
{
    []{ std::cout << "hello"; };
}

Fortunately clang issues a -Wunused-value warning for the lambda expression, since it's never evaluated/used.

However gcc does not issue any warning at all. Is there a way to warn about this buggy code when compiling with gcc?

There is a related post about unused lambda captures here which is similar, but this question is for unused lambda expressions themselves.

1 Answers

GCC has warning option -Wunused which enables all warnings about unused pieces of code. The latest (trunk) GCC does not warn about the unused lambda with options -Wunused -Wall -Wextra. Therefore my conclusion is that there is no way to enable a warning that warns about the shown program in GCC at this moment.

Related