https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81757
Bug ID: 81757
Summary: function reference on nonnull and noexcept
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: patrick.a.moran at gmail dot com
Target Milestone: ---
Created attachment 41948
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41948&action=edit
a minimal reproduction
We have noticed a behavior that we believe to be a bug. It appears in the
recent 7.2 release candidate, and we know for sure that the behavior was not
present in 6.3. It manifests in --std=c++17 or --std=c++1z.
I have attached a minimal reproduction.
g++ --std=c++17 -c repro.cpp
We get a failure to compile with the following message
----------
error: invalid initialization of reference of type ‘void (&)(void*) noexcept’
from expression of type ‘void(void*) noexcept’
void do_stuff() { test(foo); }
^
note: in passing argument 1 of ‘void test(TFunction&&) [with TFunction = void
(&)(void*) noexcept]’
void test(TFunction&& function);
----------
We encounter the error only if _all_ the following conditions are met:
1. The function passed as an argument takes a pointer-typed argument is forward
declared with __attribute__((nonnull(n))) (With "n" replaced with the 1-based
index of the pointer-typed argument).
2. The function is declared noexcept
3. That function is passed as an argument to another function via forwarding
reference