When a generic lambda calls a function templates declared noreturn, we still get warnings about missing return values. $ cat foo.cc template <typename T> [[noreturn]] int f(T) { throw "error"; } int g() { f(12); } template <typename T> int h(T) { f(12); } int main() { auto g = [](auto a) -> int { f(a); }; } $ g++-mp-6 --version g++-mp-6 (MacPorts gcc6 6.2.0_2) 6.2.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++-mp-6 -std=c++14 foo.cc -Wreturn-type foo.cc: In lambda function: foo.cc:21:38: warning: no return statement in function returning non-void [-Wreturn-type] auto g = [](auto a) -> int { f(a); }; ^ $ clang++-mp-3.9 -std=c++14 foo.cc -Wreturn-type $ Please note that: - if f is not templated, there is no warning - if the lambda is not generic, there is no warning - if calling from a function template rather than from a generic template (i.e., the function h), it does not trigger any warning (even if I do use h).
Also observed with GCC 7. $ g++-mp-7 -std=c++14 foo.cc -Wreturn-type foo.cc: In lambda function: foo.cc:21:38: warning: no return statement in function returning non-void [-Wreturn-type] auto g = [](auto a) -> int { f(a); }; ^ $ g++-mp-7 --version g++-mp-7 (MacPorts gcc7 7-20170101_0) 7.0.0 20170101 (experimental) Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Reconfirmed with the top of trunk (GCC 9).
Looks to be fixed in GCC 10 though.
Yes this was the same issue as PR 94742 . I will note in the original testcase, the f call inside h was not a depedent call would have been resolved and if you make it a depedent call, then you run into the same issue as the generic lambda. Or if you change the call to f inside the generic lambda to being non-depedent, you don't get the warning. So this is all fixed with a testcase added already.