Bug#877838: clang-5.0: c++17 std::get(std::variant) fails to compile with libstdc++

Daniele Di Proietto daniele.di.proietto at gmail.com
Sat Oct 7 02:57:52 UTC 2017


It appears that clang is ignoring a friend declaration, while gcc is not.

This simplified version of the program shows the problem:

$ cat variant.cpp
namespace __detail {
namespace __variant {

template <typename T>
decltype(auto) __get(const T &t) {
  return t.i_;
}

}
}

template <typename T> class variant {
public:
  variant(const T &t) : i_(t) {}
  template <typename Type>
  friend decltype(auto) __detail::__variant::__get(const Type &);
private:
  T i_;
};

int main() {
  variant v{2};
  return __detail::__variant::__get(v);
}


$ g++-7 variant.cpp -std=c++1z
$ clang++-5.0 variant.cpp -std=c++1z
variant.cpp:6:12: error: 'i_' is a private member of 'variant<int>'
  return t.i_;
           ^
variant.cpp:24:31: note: in instantiation of function template
specialization '__detail::__variant::__get<variant<int> >' requested
here
  return __detail::__variant::__get(v);
                              ^
variant.cpp:18:5: note: declared private here
  T i_;
    ^
1 error generated.

I suspect this might be related to the use of decltype(auto), but I
don't know anything about clang internals to investigate more.

I've also tried clang-6.0 from unstable and the output is similar.

I'd appreciate any help.

Thanks!

Daniele



More information about the Pkg-llvm-team mailing list