https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108414
Bug ID: 108414 Summary: template meta programming Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: amewo22370 at gmail dot com Target Milestone: --- Created attachment 54276 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54276&action=edit archive with source code and preprocessed files gcc of version 12.2.0 and linux 5.15.83-1-lts I have attached the source code. If you compile test code with line 36 commented out and line 37 uncommented, then the compiler gives an error. But if you uncomment line 36 and comment out line 37, the compiler compiles the code without errors, but the result is incorrect. Description of the code: template alias 'template<std::size_t I, typename T> using nth_type_t;' must return type with index I, that contains in type list 'T'. Comilator commands: gcc -v -save-temps -std=c++20 -lstdc++ test_line36.cpp -o test_line36 gcc -v -save-temps -std=c++20 -lstdc++ test_line37.cpp -o test_line37 Also added attachments according to bug reporting instructions. Compilation error with 'gcc -v -save-temps -std=c++20 -lstdc++ test_line37.cpp -o test_line37': Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-o' 'test_line37' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/cc1plus -E -quiet -v -D_GNU_SOURCE test_line37.cpp -mtune=generic -march=x86-64 -std=c++20 -fpch-preprocess -o test_line37.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../include/c++/12.2.0 /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../include/c++/12.2.0/x86_64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../include/c++/12.2.0/backward /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-o' 'test_line37' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/cc1plus -fpreprocessed test_line37.ii -quiet -dumpbase test_line37.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++20 -version -o test_line37.s GNU C++20 (GCC) version 12.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.25-GMP warning: MPFR header version 4.1.0-p13 differs from library version 4.1.1-p1. warning: MPC header version 1.2.1 differs from library version 1.3.0. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++20 (GCC) version 12.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.25-GMP warning: MPFR header version 4.1.0-p13 differs from library version 4.1.1-p1. warning: MPC header version 1.2.1 differs from library version 1.3.0. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 402ce889a414e2a3abbbe3146fa0a6cb test_line37.cpp: In substitution of ‘template<long unsigned int I, class T> using nth_type_t = typename nth_type::type [with long unsigned int I = 0; T = type_list<int, float, double>]’: test_line37.cpp:49:36: required from here test_line37.cpp:41:7: error: no type named ‘type’ in ‘struct nth_type<0, type_list<int, float, double> >’ 41 | using nth_type_t = typename nth_type<I, T>::type; | ^~~~~~~~~~ test_line37.cpp: In substitution of ‘template<long unsigned int I, class T> using nth_type_t = typename nth_type::type [with long unsigned int I = 1; T = type_list<int, float, double>]’: test_line37.cpp:50:36: required from here test_line37.cpp:41:7: error: no type named ‘type’ in ‘struct nth_type<1, type_list<int, float, double> >’ test_line37.cpp: In substitution of ‘template<long unsigned int I, class T> using nth_type_t = typename nth_type::type [with long unsigned int I = 2; T = type_list<int, float, double>]’: test_line37.cpp:51:36: required from here test_line37.cpp:41:7: error: no type named ‘type’ in ‘struct nth_type<2, type_list<int, float, double> >’ test_line37.cpp: In function ‘int main()’: test_line37.cpp:53:25: error: ‘elm0’ was not declared in this scope 53 | std::cout << typeid(elm0).name() << std::endl; | ^~~~ test_line37.cpp:54:25: error: ‘elm1’ was not declared in this scope 54 | std::cout << typeid(elm1).name() << std::endl; | ^~~~ test_line37.cpp:55:25: error: ‘elm2’ was not declared in this scope 55 | std::cout << typeid(elm2).name() << std::endl; |