<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59292>59292</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang fails to compile apparently valid C++ code with forward declared/incomplete types
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          leonleon77
      </td>
    </tr>
</table>

<pre>
    Hi, there is thinking that it could be a bug in Clang (tried with 15 as well as trunk).
Original discussion as per 
https://gcc.gnu.org/pipermail/gcc-help/2022-December/142044.html 
and 
https://gcc.gnu.org/pipermail/gcc-help/2022-December/142047.html

the code below reproduces the issue (GCC 12.2 -std=c++20 compiles fine, MSVC19.33 /std:c++20 compiles fine, Clang 15.0.0 and trunk -std=c++20 barf)

#include <memory>
#include <vector>
#include <optional>

struct X;

template <typename T>
struct J {
 typedef typename T::x aoeu;
};

struct S {
 ::std::vector<::std::shared_ptr<J<X>>> v;
};

static ::std::optional<S> opt;

struct X {
    typedef int x;
};

int main () {
}

Clang barfs with: incomplete type 'X' named in nested name specifier typedef typename T::x aoeu (if one makes struct X a template the textual error changes but semantics remain the same more or less)...

Interestingly if S::v is not a vector, i.e. instead of
::std::vector<::std::shared_ptr<J<X>>> v;
v is just
::std::shared_ptr<J<X>> v;

... then clang compiles fine. 

The thoughts on GCC email list are that since no instantiation takes place (shared_ptr) then the code should compile. 

As LIU Hao comments in that second link above: I think this is a bug in Clang. Instantiation of `shared_ptr<T<U>>` is not meant to instantiate `T<U>`. Your code actually compiles fine if the definition of `J` was not provided.

Kind regards
Leon
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVsFy2zgPfhr6golGoqLIOvjgKL__ptudPaTdyZ52KBKS2FCkhqTs-u13ILmOnW2zl84k1FgAPgAfIIAiBN1ZxA0r7lnxsBJT7J3fGHSW_sty1Th13Hz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