-1

I was writing code with plenty of templated classes and have encountered a problem when in a class I needed to use a templated alias from another templated class. I wrote the code and everything was fine until this code was attempted to be compiled on Ubuntu 20.04 which is packed with G++9. Without going too much in-detail here is the short snippet that reproduces the problem perfectly:

#include <vector>

template <typename A> struct S1 {
    template <typename D> using VT = std::vector<D>;
};

template <typename A> struct S2 {
    template <typename D> using VT = typename S1<A>::VT<D>;
};


int main() {
    S2<int> s;
    return 0;
}

Compiling this on my own Arch machine with G++ 11.2.0 is completely fine, but when I try to do the same with G++ 9.4.0, it fails with:

test.cpp:8:53: error: expected ‘;’ before ‘<’ token
    8 |  template <typename D> using VT = typename S1<A>::VT<D>;
      |                                                     ^
      |                                                     ;

Is there any particular change made to G++ that's causing that? Why was it implemented, is it a part of C++17 standard? And, most importantly, is there any sensible way to provide functionally the same code that will work with G++9?

  • @Jarod42 this is it, thanks! I guess your way is the standard, but is there any info as to why the change was made to also accept the code as I wrote it in the later verions? – GregTheMadMonk May 23 '22 at 18:35
  • Compiler extensions/bug I would say. (I would say error should be spot on the first pass of the [two-phase name lookup](https://en.cppreference.com/w/cpp/language/two-phase_lookup)). – Jarod42 May 24 '22 at 07:47

0 Answers0