Alexander Huszagh Alexander Huszagh - 5 months ago 48
C++ Question

Class Name Injection and Constructors

Recently, upon updating a library to Clang 5.x, I noticed a bug in my code that had compiled previously on Clang 4.x, GCC 5.x-6.x, and MSVC 2015 and 2017.

#include <iostream>
#include <typeinfo>
#include <vector>

int main()
using a = typename std::vector<int>::vector;
std::cout << typeid(a).name() << std::endl;
return 0;

Clang produces the following warning message, while all other compilers silently compile the above code:

a.cpp:7:42: warning: ISO C++ specifies that qualified reference to 'vector' is a
constructor name rather than a type in this context, despite preceding
'typename' keyword [-Winjected-class-name]
using a = typename std::vector<int>::vector;

Which compiler is buggy? Am I correct in assuming that Clang5.x has the correct behavior here, and all the other compilers (and versions) are incorrect. If so, is this worth submitting bug reports to MSVC and GCC?

Answer Source

Clang-5 is very much correct. Over at [class.qual]/2:

In a lookup in which function names are not ignored and the nested-name-specifier nominates a class C:

  • if the name specified after the nested-name-specifier, when looked up in C, is the injected-class-name of C
  • ...

the name is instead considered to name the constructor of class C.

As for the other part of the question. Yes, it's definitely worth it to submit bug reports. Standard compliance (or at least more diagnostics towards it) are to be encouraged IMO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download