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

--- Comment #2 from ASA <aaron_sami_abassi at hotmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> 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.

It was a late night.  You are correct that it is producing a function pointer,
not a new function instance.  I re-submitted the bug as id 85509 with correct
details and sample code.  Thank you, my apologies for not sleeping before I
tried to submit a bug report.

Reply via email to