Hi,

I'm hoping a C++ language expert can help me with scoping rules for named 
function parameters.


As background, I'd like to allow named function parameters in non-function 
declarations (such as function-pointer-typed variables) to be referenced in 
attribute expressions.  Currently, attempting to do so results in "use of 
undeclared identifier".  However, I'm not even sure the standard allows me to 
do this, let alone what assumptions any patch to clang might run afoul of.


Consider the declaration:


    void (*pFn)(int x);


Reading the standard (specifically, I'm looking at C++11 draft N4527), I gather 
that:

?1. pFn is not a "function declarator". I didn't see a clear definition of 
this, but I assume function and variable are mutually exclusive descriptions of 
a declarator, and that this would be a variable declarator.

2. According to [basic.scope.proto] (3.3.4), named parameters inside function 
declarators which are not also definitions have function prototype scope, but 
this only applies to function declarators.  I do not find a scoping rule that 
would apply to x in my pFn example, assuming point 1 is correct.


This seems like x has no applicable scoping rule and you shouldn't be able to 
reference it.  However, I note the following declaration is accepted as valid 
C++11:


    auto (*pSum)(int x, double y) -> decltype(x + y);


I'd appreciate any help understanding what portions of the standard apply to my 
examples and how to interpret them, and whether the standard in fact allows me 
to place an attribute on pFn which references x.



Thanks,

David Fontaine

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users

Reply via email to