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

            Bug ID: 106613
           Summary: GCC rejects valid program involving std::invariant
                    saying incomplete type
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following valid(afaik) program is rejected by gcc.
https://godbolt.org/z/e73Yf4s47

```
#include <variant>

struct LiteralExpr
{
    int value;
};

template <typename T>
struct BaseSpace
{
    struct AddExpr;
    struct AddExprBox
    {
        const AddExpr &_impl;

    public:
        AddExprBox(const AddExpr &obj) {}
    };
    using Expr = std::variant<AddExprBox, LiteralExpr>;
    struct AddExpr
    {
        std::variant<AddExprBox, LiteralExpr> lhs;  // error:
'BaseSpace<T>::AddExpr::lhs' has incomplete type
    };
};

auto main() -> int
{
    auto expr = BaseSpace<int>::Expr(LiteralExpr{2});
}
```

The error says:

```
error: 'BaseSpace<T>::AddExpr::lhs' has incomplete type
   22 |         std::variant<AddExprBox, LiteralExpr> lhs;
      |                                               ^~~
In file included from <source>:1:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/variant:1336:11: note:
declaration of 'class std::variant<BaseSpace<int>::AddExprBox, LiteralExpr>'
 1336 |     class variant
      |           ^~~~~~~
```

Reply via email to