which compiler is right (either to compile or to barf)...

leon zadorin leonleon77@gmail.com
Thu Dec 1 04:51:58 GMT 2022


Hi everyone,

I would be interested to hear the opinions of C++ standard experts on which
compiler is correctly dealing with the below code (GCC 12.2 -std=c++20
 compiles fine, MSVC19.33 /std:c++20 compiles fine, Clang 15.0.0 -std=c++20
barfs)


#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

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.

Also, if optional is replaced with say unique_ptr, clang also builds fine.

I would be interested in being educated on the standard (of which I am not
a lawyer :) ) what would be the correctly mandated behavior?

Kind regards
Leon.


More information about the Gcc-help mailing list