cplusplus / cplusplus/draft

[conv.fcttpr] Clarify the definition and the corresponding examples

Open
#5,822 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[conv.fctptr] p1 says

A prvalue of type “pointer to noexcept function” can be converted to a prvalue of type “pointer to function”. The result is a pointer to the function.

Presumably, the definition works if and only if such two pointers point to the same function type except for exception specification. In the current wording, we seem not to give the restriction to the function types in the establishment of the conversion.

Suggested resolution

A prvalue of type “pointer to function type T” can be converted to a prvalue of type “pointer to function type U” where T and U are the same function type except that T has a non-throwing exception specification and U has a potentially-throwing exception specification. The result is a pointer to the function.

The same is true for the pointer to member function conversion.

In the current examples, the listed case is a bit irrelevant to the conversion

void (*p)();
void (**pp)() noexcept = &p;    // error: cannot convert to pointer to noexcept function

The definition works only if we have a "pointer to function type" rather than "pointer to pointer to function type". Even though, the example would be

void (*p)() noexcept;
void (**pp)() = &p;

The relevant example should be changed to

void (*p)() noexcept;
void(*p1)() = p;  // ok

void(*p2)() noexcept = p1;  // error

struct S{
    void fun() noexcept {}
};
void(S::*p3)()= &S::fun;
void(S::*p4)() noexcept = p3;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading [conv.fctptr] p1 and the conversion examples quoted in the issue. Compare the wording and examples with the proposed function-pointer and pointer-to-member-function cases; the work is done when the restriction on function types and the corresponding valid and invalid conversions are clearly represented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.