Bug 79021 - attribute noreturn on function template ignored in generic lambda
Summary: attribute noreturn on function template ignored in generic lambda
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.2.0
: P3 normal
Target Milestone: 8.5
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, diagnostic, needs-bisection
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2017-01-07 13:26 UTC by Akim Demaille
Modified: 2023-10-19 22:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0, 8.5.0, 9.4.0
Known to fail: 6.4.0, 7.3.0, 7.5.0, 8.2.0, 8.4.0, 9.0, 9.3.0
Last reconfirmed: 2018-04-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Akim Demaille 2017-01-07 13:26:31 UTC
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).
Comment 1 Akim Demaille 2017-01-08 10:40:11 UTC
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.
Comment 2 Martin Sebor 2018-09-14 20:00:51 UTC
Reconfirmed with the top of trunk (GCC 9).
Comment 3 Andrew Pinski 2023-10-19 22:25:04 UTC
Looks to be fixed in GCC 10 though.
Comment 4 Andrew Pinski 2023-10-19 22:32:23 UTC
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.