The problem of cyclic dependency with inheritance

Open
#835 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Reproduce the failure by varying whether C-class.h or D-class.h is included first in a C++ translation unit, then inspect the generated class headers and the g++ error. Done means the hierarchy compiles regardless of header order, or KPHP reports a human-readable diagnostic instead of the g++ stage error.

Written by the indexing model from the issue text.

Description

bug

Assume we have the following class hierarchy:
image
There is a a possible situation when such a hierarchy cannot be compiled. For example, if in any C++ Translation Unit inclusion of "С-class.h" or "D-class.h" will precede all other class headers of this hierarchy. The reason is in mechanism of header inclusion in KPHP.

A possible solution is following:

  1. To stop include class definition headers for properties and use only incomplete declarations.
  2. Include full class definitions for functions that uses such properties

Or we could just detect such situations and give human-readable error; for now it's g++ stage error:

...
error: expected class-name before ‘{’ token:
struct C$D: public C$D {
...

But, as I believe, the solution or detection would require analysis, which would take considerable time..

Dominant language
C++
Stars
1.5k
Forks
116
Avg merge
5d 17h
Merged PRs (30d)
11

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.

More from VKCOM/kphp

All issues in VKCOM/kphp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.