KhronosGroup / KhronosGroup/OpenXR-Hpp
Forward declare header can't be used to forward declare Unique Handles
- Dominant language
- C++
- Stars
- 50
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use the forward headers to limit the scope of my include of `openxr.hpp` by only using it in one cpp file.
Normally to do this, you forward declare your classes in the header files and include the full headers in the cpp files.
From the docustring, I would expect to be able to use Unique Handles like a unique ptr.
> Template class for holding a handle with unique ownership, much like unique_ptr.
Below is an example, it would work if using an `std::unique_ptr` because the undefined deleter is referenced in the cpp file and not the header.
A.hpp
```c++
#pragma once
#include
struct A {
A();
virtual ~A();
xr::UniqueInstance m_instance;
};
```
A.cpp
```c++
#include "A.h"
#include
A::A() = default;
A::~A() = default; // Here the deleter is defined and since it has visibility of openxr.hpp it should be okay
```
In practice, you get the following errors because the forward header implements functions that need full visibility of the forward declared classes and even holds an instance of the type in question.
```
openxr/openxr_handles_forward.hpp(140,18): error C2027: use of undefined type 'xr::Instance'
openxr/openxr_handles_forward.hpp(140,32): error C3646: 'getRawHandle': unknown override specifier
openxr/openxr_handles_forward.hpp(151,18): error C2027: use of undefined type 'xr::Instance'
openxr/openxr_handles_forward.hpp(170,8): error C2079: 'xr::UniqueHandle::m_value' uses undefined class 'xr::Instance
```
An awkward workaround is to make `m_instance` into a `std::unique_ptr`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with openxr/openxr_handles_forward.hpp and compare its UniqueHandle implementation with the full definitions in openxr/openxr.hpp. Reproduce the errors using the A.hpp/A.cpp example, then determine how the forward header can support a UniqueInstance member without requiring the complete handle type; done means the example compiles with the full include confined to A.cpp.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100