[Bug c++/126894] New: [contracts] Incorrectly mark a parameter as ODR-used when a pack indexing expression is used in a postcondition.

"zheng.xianyuwang at gmail dot com via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126894

            Bug ID: 126894
           Summary: [contracts] Incorrectly mark a parameter as ODR-used
                    when a pack indexing expression is used in a
                    postcondition.
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: c++-contracts
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zheng.xianyuwang at gmail dot com
  Target Milestone: ---

Consider the following example:

```
template <typename... Args>
  void f (Args... args)
    post (args...[1])
  {}


template void f<int, int&> (int, int&);
```

In the postcondition, only `args...[1]' is ODR-used, so when checking the rule
that “a non-reference parameter used in a postcondition must have const type”,
we should likewise only check `args...[1]'.

The current trunk build incorrectly diagnoses:

`error: value parameter 'args#0' used in a postcondition must be const'

This is probably because, in cp_parser_primary_expression, finish_id_expression
-> check_param_in_postcondition marks `args' as used-in-post before
cp_parser_pack_index processes the pack indexing expression. This then causes
check_postconditions_in_redecl to issue the erroneous diagnostic.

Since check_postconditions_in_redecl on trunk also has a one-to-many mapping
problem when instantiating parameter packs (PR124395), the following case is
still missing a diagnostic:

```
extern template void f<int&, int> (int&, int);
```
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.