https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95116
Bug ID: 95116 Summary: [C++ 20] Accepts invalid code with decltype dependent type Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ojman101 at protonmail dot com Target Milestone: --- The code below is invalid. The keyword "typename" needs to be inserted before the decltype expression as "bar" is a dependent type (dependent on template type T). template <typename T> struct Bar { using bar_type = int; }; template <typename T> struct Foo { Bar<T> bar; using foo_type = decltype(bar)::bar_type; }; int main() { // Instantiate Foo template Foo<int> foo; } The code successfully compiles with GCC 9.3.0 when running the command "g++ -std=c++2a main.cpp". Note that the "-std=c++2a" must be passed. When passing "-std=c++17", GCC successfully detects the error and prints: main.cpp:10:22: error: need 'typename' before 'decltype (((Foo<T>*)(void)0)->Foo<T>::bar)::bar_type' because 'decltype (((Foo<T>*)(void)0)->Foo<T>::bar)' is a dependent scope 10 | using foo_type = decltype(bar)::bar_type; | ^~~~~~~~ | typename Running clang 10 with the command "clang++ -std=c++2a main.cpp" also successfully detects the error and prints: main.cpp:10:22: error: missing 'typename' prior to dependent type name 'decltype(bar)::bar_type' using foo_type = decltype(bar)::bar_type; ^~~~~~~~~~~~~~~~~~~~~~~ typename 1 error generated.