[Bug c++/79508] New: Parse error in template argument list using nested template arguments

trufanovan at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 14 13:23:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79508

            Bug ID: 79508
           Summary: Parse error in template argument list using nested
                    template arguments
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: trufanovan at gmail dot com
  Target Milestone: ---

Created attachment 40738
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40738&action=edit
ii file

It's probably a regression.
I was trying to compile a popular opensourse project on my Kubuntu 16.10
4.8.0-38-generic with gcc 6.2.0 20161005 and got a compilation error.
The original problem was reported to project authors on GitHub:
https://github.com/JohnLangford/vowpal_wabbit/issues/1183
We found out that it's gcc version specific - it works for clang and gcc
4.6-4.9.

I've simplified the code. The sample to reproduce the problem is:

> code start: t.cpp
class C
{
public: 
    template< void(*F)()> void set_default() {  }       
};


template <class T> void random_positive()
{
}

template<class T> void initialize(T& x)
{
x.template set_default<random_positive<T> >();
}

int main ()
{
    C x;
    initialize<C>(x);
}
>code end: t.cpp

I'm getting 

> compilation output:
t.cpp: In function ‘void initialize(T&)’:
t.cpp:18:12: error: parse error in template argument list
 x.template set_default<random_positive<T> >();
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.cpp:18:12: error: expected identifier

> compilation output end

Below are commad lines for old g++ and clangs that doesn't cause the problem so
produce no output to console + the command line of g++-6 with all verbose :


>truf@truf-laptop:~$ clear
>truf@truf-laptop:~$ /usr/bin/g++-4.6  -Wall -Wextra -c t.cpp -o t.o
>truf@truf-laptop:~$ /usr/bin/g++-4.8  -Wall -Wextra -c t.cpp -o t.o
>truf@truf-laptop:~$ /usr/bin/g++-4.9  -Wall -Wextra -c t.cpp -o t.o
>truf@truf-laptop:~$ /usr/bin/clang++-3.6  -Wall -Wextra -c t.cpp -o t.o
>truf@truf-laptop:~$ /usr/bin/clang++-3.8  -Wall -Wextra -c t.cpp -o t.o
>truf@truf-laptop:~$ /usr/bin/g++-6  -Wall -Wextra -c t.cpp -o t.o
t.cpp: In function ‘void initialize(T&)’:
t.cpp:18:12: error: parse error in template argument list
 x.template set_default<random_positive<T> >();
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.cpp:18:12: error: expected identifier
>truf@truf-laptop:~$ /usr/bin/g++-6  -v -save-temps -Wall -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -c t.cpp -o t.o
Using built-in specs.
COLLECT_GCC=/usr/bin/g++-6
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.2.0-5ubuntu12'
--with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-fno-aggressive-loop-optimizations' '-c' '-o' 't.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/6/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE t.cpp -mtune=generic -march=x86-64 -Wall -Wextra
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations
-fpch-preprocess -fstack-protector-strong -Wformat-security -o t.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/6"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/6
 /usr/include/x86_64-linux-gnu/c++/6
 /usr/include/c++/6/backward
 /usr/lib/gcc/x86_64-linux-gnu/6/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/6/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-fno-aggressive-loop-optimizations' '-c' '-o' 't.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/6/cc1plus -fpreprocessed t.ii -quiet -dumpbase
t.cpp -mtune=generic -march=x86-64 -auxbase-strip t.o -Wall -Wextra -version
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations
-fstack-protector-strong -Wformat-security -o t.s
GNU C++14 (Ubuntu 6.2.0-5ubuntu12) version 6.2.0 20161005 (x86_64-linux-gnu)
        compiled by GNU C version 6.2.0 20161005, GMP version 6.1.1, MPFR
version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (Ubuntu 6.2.0-5ubuntu12) version 6.2.0 20161005 (x86_64-linux-gnu)
        compiled by GNU C version 6.2.0 20161005, GMP version 6.1.1, MPFR
version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: df259ea45bcfc8adc9cf4871d1d696af
t.cpp: In function ‘void initialize(T&)’:
t.cpp:18:12: error: parse error in template argument list
 x.template set_default<random_positive<T> >();
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.cpp:18:12: error: expected identifier
truf@truf-laptop:~$


More information about the Gcc-bugs mailing list