[Bug c++/104255] parsing function signature fails when it uses a function parameter outside of an unevaluated context

ppalka at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 2 15:13:01 GMT 2022


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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to qingzhe huang from comment #4)
> (In reply to Patrick Palka from comment #2)
> 
> > 
> >   error: use of parameter outside function body before ‘)’ token
> > 
> > due to 'e' being used outside of an unevaluated context within the signature
> > of the function.
> 
> Sorry for my being unable to grasp your meaning before. Now I can see your
> point that the "e" of A<f(e)> is from declaration of parameter of function
> "g". Now that we agree the value from parameter clause should not be used in
> trailing return type, then it should also not be used in requires clause
> etc. 
> (https://eel.is/c++draft/basic.scope.param#1.3)
> But this works:
> 
> template<typename T>
> auto f(int n) requires (n>0);

That's because the constraint-expression of a requires clause is an unevaluated
operand (wg21.link/temp.pre#9.sentence-4).  (Though I think this example is
strictly speaking ill-formed no diagnostic required because the constraint can
never be satisfied (wg21.link/temp.res.general#6.2).)

The check in question is in finish_id_expression_1:

      /* Also disallow uses of function parameters outside the function
         body, except inside an unevaluated context (i.e. decltype).  */
      if (TREE_CODE (decl) == PARM_DECL
          && DECL_CONTEXT (decl) == NULL_TREE
          && !cp_unevaluated_operand)
        {
          *error_msg = G_("use of parameter outside function body");
          return error_mark_node;
        }

> 
> This is violating our assumption. So, I am not convinced that 
> (https://eel.is/c++draft/basic.scope.param#note-1)
> "A function parameter cannot be used for its value within the
> parameter-declaration-clause" is really meaningful. Or I misunderstand it???

We should probably relax the above check to permit uses of function parameters
with empty types even outside of unevaluated contexts, since we don't really
care about the value of an empty type.


More information about the Gcc-bugs mailing list