https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85500

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is not a valid bug report, see https://gcc.gnu.org/bugs/ for what we
require.

(In reply to ASA from comment #0)
> When initializing an auto variable from a function identifier, GNU C++ is
> incorrectly defining a new function.
> 
> The statement:
> 
> auto variable_name = function_name;
> 
> Will define a function or nested function depending on the scope of
> reference named variable_name.  This is not a pedantically correct
> interpretation of the C++ source code as only variables can be initialized.


Here's a complete program:

#include <type_traits>

int function_name() { return 0; }

auto variable_name = function_name;

static_assert(std::is_pointer<decltype(variable_name)>::value, "");

int main()
{
    return (*variable_name)();
}

This shows that your statement is not creating a new function, it's a pointer
to function. You cannot copy functions or declare them as variables, so the
'auto' declaration performs function-to-pointer decay and so deduces a function
pointer type not a function type.

> 
> Also be careful in your bug correction:
> 
> auto function_name;
> 
> Should still be treated as a function declaration when initialization is not
> present (as of C++14).

No, that's not valid as a function declaration.

Reply via email to