C++ Logo

std-discussion

Advanced search

Re: The scope of the function-local predefined variable.

From: Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Date: Mon, 12 Dec 2022 13:02:23 +0300
 
However there is also written in the C++ 2- Standard ( 6.4.4 Function parameter scope)
«1 A function parameter (including one appearing in a lambda-declarator) or function-local predefined variable (9.5) has function parameter scope. The potential scope of a parameter or function-local predefined variable begins at its point of declaration. If the nearest enclosing function declarator is not the declarator of a function definition, the potential scope ends at the end of that function declarator.»
 
So how does the example of the function declaration contradict to this quote?
 
With best regards
(Vlad from Moscow)
 
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
 
  
>Понедельник, 12 декабря 2022, 5:19 +03:00 от Andrew Schepler <aschepler_at_[hidden]>:
>
>On Thu, Dec 8, 2022 at 11:32 AM Vladimir Grigoriev via Std-Discussion < std-discussion_at_[hidden] > wrote:
>>Well, and what about this declaration
>>
>>void h( auto x ) requires requires { sizeof ( x ) == sizeof __func__; };
>>
>>Is it valid?
>
>Still no. The term "function-local predefined variable" and the variable __func__ are described in [dcl.fct.def.general] in the context of a function definition. Since this is not a function definition, there are no function-local predefined variables. No __func__ variable exists for this code at all, so statements about its scope don't apply.
>
>>
>>As it is said in the Standard the function-local predefined variable has function parameter scope.
>>
>>With best regards
>>(Vlad from Moscow)
>>You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>>
>>
>>>Четверг, 8 декабря 2022, 15:24 +03:00 от language.lawyer_at_[hidden] :
>>> 
>>>> According to the C++ 20 Standard (Reference: 6.4.4 Function parameter scope)
>>>> «1 A function parameter (including one appearing in a lambda-declarator) or function-local predefined variable (9.5) has function parameter scope….»
>>>
>>>The next sentence: «The potential scope of a parameter or function-local predefined variable begins at its point of declaration»
>>>
>>>[basic.scope.pdecl]/9: «The point of declaration for a function-local predefined variable is immediately before the function-body of a function definition.»
>>>
>>>> So should this function declaration be valid?
>>>>
>>>> void f( size_t n = sizeof __func__ );
>>>
>>>No.
>>>
>>>> Pay attention to that there is used a function declaration that is not the function definition.
>>>
>>>There is no point of declaration of __func__ here, then.
>> --
>>Std-Discussion mailing list
>>Std-Discussion_at_[hidden]
>>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
 

Received on 2022-12-12 10:02:48